From 43312fcf86223d10b2dc51479c42176e3b9eb6bb Mon Sep 17 00:00:00 2001 From: Xingyu Xu Date: Wed, 12 Jun 2019 02:03:57 +0800 Subject: [PATCH] feat: TypeScript type definition (#23) --- .../building-from-scratch/package-lock.json | 48 +++++--------- index.d.ts | 2 + models/Artboard/index.d.ts | 20 ++++++ models/AttributedString/index.d.ts | 11 ++++ models/Border/index.d.ts | 20 ++++++ models/BorderOptions/index.d.ts | 23 +++++++ models/Color/index.d.ts | 17 +++++ models/CurvePoint/index.d.ts | 14 +++++ models/Document/index.d.ts | 52 ++++++++++++++++ models/ExportFormat/index.d.ts | 13 ++++ models/ExportOptions/index.d.ts | 12 ++++ models/Fill/index.d.ts | 25 ++++++++ models/Gradient/index.d.ts | 26 ++++++++ models/Group/index.d.ts | 11 ++++ models/Layer/index.d.ts | 40 ++++++++++++ models/Meta/index.d.ts | 33 ++++++++++ models/Oval/index.d.ts | 13 ++++ models/Page/index.d.ts | 18 ++++++ models/Rect/index.d.ts | 11 ++++ models/Rectangle/index.d.ts | 15 +++++ models/RulerData/index.d.ts | 9 +++ models/Shadow/index.d.ts | 20 ++++++ models/ShapeGroup/index.d.ts | 15 +++++ models/SharedStyle/index.d.ts | 16 +++++ models/Sketch/index.d.ts | 41 ++++++++++++ models/StringAttribute/index.d.ts | 28 +++++++++ models/Style/index.d.ts | 62 +++++++++++++++++++ models/SymbolInstance/index.d.ts | 10 +++ models/SymbolMaster/index.d.ts | 10 +++ models/Text/index.d.ts | 15 +++++ models/TextStyle/index.d.ts | 34 ++++++++++ models/User/index.d.ts | 12 ++++ models/index.d.ts | 53 ++++++++++++++++ package-lock.json | 24 +++++++ package.json | 10 ++- tsconfig.json | 60 ++++++++++++++++++ utils/index.d.ts | 23 +++++++ 37 files changed, 830 insertions(+), 36 deletions(-) create mode 100644 index.d.ts create mode 100644 models/Artboard/index.d.ts create mode 100644 models/AttributedString/index.d.ts create mode 100644 models/Border/index.d.ts create mode 100644 models/BorderOptions/index.d.ts create mode 100644 models/Color/index.d.ts create mode 100644 models/CurvePoint/index.d.ts create mode 100644 models/Document/index.d.ts create mode 100644 models/ExportFormat/index.d.ts create mode 100644 models/ExportOptions/index.d.ts create mode 100644 models/Fill/index.d.ts create mode 100644 models/Gradient/index.d.ts create mode 100644 models/Group/index.d.ts create mode 100644 models/Layer/index.d.ts create mode 100644 models/Meta/index.d.ts create mode 100644 models/Oval/index.d.ts create mode 100644 models/Page/index.d.ts create mode 100644 models/Rect/index.d.ts create mode 100644 models/Rectangle/index.d.ts create mode 100644 models/RulerData/index.d.ts create mode 100644 models/Shadow/index.d.ts create mode 100644 models/ShapeGroup/index.d.ts create mode 100644 models/SharedStyle/index.d.ts create mode 100644 models/Sketch/index.d.ts create mode 100644 models/StringAttribute/index.d.ts create mode 100644 models/Style/index.d.ts create mode 100644 models/SymbolInstance/index.d.ts create mode 100644 models/SymbolMaster/index.d.ts create mode 100644 models/Text/index.d.ts create mode 100644 models/TextStyle/index.d.ts create mode 100644 models/User/index.d.ts create mode 100644 models/index.d.ts create mode 100644 tsconfig.json create mode 100644 utils/index.d.ts diff --git a/__examples__/building-from-scratch/package-lock.json b/__examples__/building-from-scratch/package-lock.json index ebb7f80..072d5fa 100644 --- a/__examples__/building-from-scratch/package-lock.json +++ b/__examples__/building-from-scratch/package-lock.json @@ -7,26 +7,22 @@ "core-js": { "version": "2.3.0", "resolved": "https://registry.npmjs.org/core-js/-/core-js-2.3.0.tgz", - "integrity": "sha1-+rg/uwstjchfpjbEudNMdUIMbWU=", - "dev": true + "integrity": "sha1-+rg/uwstjchfpjbEudNMdUIMbWU=" }, "core-util-is": { "version": "1.0.2", "resolved": "https://registry.npmjs.org/core-util-is/-/core-util-is-1.0.2.tgz", - "integrity": "sha1-tf1UIgqivFq1eqtxQMlAdUUDwac=", - "dev": true + "integrity": "sha1-tf1UIgqivFq1eqtxQMlAdUUDwac=" }, "es6-promise": { "version": "3.0.2", "resolved": "https://registry.npmjs.org/es6-promise/-/es6-promise-3.0.2.tgz", - "integrity": "sha1-AQ1YWEI6XxGJeWZfRkhqlcbuK7Y=", - "dev": true + "integrity": "sha1-AQ1YWEI6XxGJeWZfRkhqlcbuK7Y=" }, "fs-extra": { "version": "7.0.1", "resolved": "https://registry.npmjs.org/fs-extra/-/fs-extra-7.0.1.tgz", "integrity": "sha512-YJDaCJZEnBmcbw13fvdAM9AwNOJwOzrE4pqMqBq5nFiEqXUqHwlK4B+3pUw6JNvfSPtX05xFHtYy/1ni01eGCw==", - "dev": true, "requires": { "graceful-fs": "^4.1.2", "jsonfile": "^4.0.0", @@ -36,32 +32,27 @@ "graceful-fs": { "version": "4.1.15", "resolved": "https://registry.npmjs.org/graceful-fs/-/graceful-fs-4.1.15.tgz", - "integrity": "sha512-6uHUhOPEBgQ24HM+r6b/QwWfZq+yiFcipKFrOFiBEnWdy5sdzYoi+pJeQaPI5qOLRFqWmAXUPQNsielzdLoecA==", - "dev": true + "integrity": "sha512-6uHUhOPEBgQ24HM+r6b/QwWfZq+yiFcipKFrOFiBEnWdy5sdzYoi+pJeQaPI5qOLRFqWmAXUPQNsielzdLoecA==" }, "immediate": { "version": "3.0.6", "resolved": "https://registry.npmjs.org/immediate/-/immediate-3.0.6.tgz", - "integrity": "sha1-nbHb0Pr43m++D13V5Wu2BigN5ps=", - "dev": true + "integrity": "sha1-nbHb0Pr43m++D13V5Wu2BigN5ps=" }, "inherits": { "version": "2.0.3", "resolved": "https://registry.npmjs.org/inherits/-/inherits-2.0.3.tgz", - "integrity": "sha1-Yzwsg+PaQqUC9SRmAiSA9CCCYd4=", - "dev": true + "integrity": "sha1-Yzwsg+PaQqUC9SRmAiSA9CCCYd4=" }, "isarray": { "version": "1.0.0", "resolved": "https://registry.npmjs.org/isarray/-/isarray-1.0.0.tgz", - "integrity": "sha1-u5NdSFgsuhaMBoNJV6VKPgcSTxE=", - "dev": true + "integrity": "sha1-u5NdSFgsuhaMBoNJV6VKPgcSTxE=" }, "jsonfile": { "version": "4.0.0", "resolved": "https://registry.npmjs.org/jsonfile/-/jsonfile-4.0.0.tgz", "integrity": "sha1-h3Gq4HmbZAdrdmQPygWPnBDjPss=", - "dev": true, "requires": { "graceful-fs": "^4.1.6" } @@ -70,7 +61,6 @@ "version": "3.1.5", "resolved": "https://registry.npmjs.org/jszip/-/jszip-3.1.5.tgz", "integrity": "sha512-5W8NUaFRFRqTOL7ZDDrx5qWHJyBXy6velVudIzQUSoqAAYqzSh2Z7/m0Rf1QbmQJccegD0r+YZxBjzqoBiEeJQ==", - "dev": true, "requires": { "core-js": "~2.3.0", "es6-promise": "~3.0.2", @@ -83,7 +73,6 @@ "version": "3.1.1", "resolved": "https://registry.npmjs.org/lie/-/lie-3.1.1.tgz", "integrity": "sha1-mkNrLMd0bKWd56QfpGmz77dr2H4=", - "dev": true, "requires": { "immediate": "~3.0.5" } @@ -91,20 +80,17 @@ "pako": { "version": "1.0.8", "resolved": "https://registry.npmjs.org/pako/-/pako-1.0.8.tgz", - "integrity": "sha512-6i0HVbUfcKaTv+EG8ZTr75az7GFXcLYk9UyLEg7Notv/Ma+z/UG3TCoz6GiNeOrn1E/e63I0X/Hpw18jHOTUnA==", - "dev": true + "integrity": "sha512-6i0HVbUfcKaTv+EG8ZTr75az7GFXcLYk9UyLEg7Notv/Ma+z/UG3TCoz6GiNeOrn1E/e63I0X/Hpw18jHOTUnA==" }, "process-nextick-args": { "version": "1.0.7", "resolved": "https://registry.npmjs.org/process-nextick-args/-/process-nextick-args-1.0.7.tgz", - "integrity": "sha1-FQ4gt1ZZCtP5EJPyWk8q2L/zC6M=", - "dev": true + "integrity": "sha1-FQ4gt1ZZCtP5EJPyWk8q2L/zC6M=" }, "readable-stream": { "version": "2.0.6", "resolved": "https://registry.npmjs.org/readable-stream/-/readable-stream-2.0.6.tgz", "integrity": "sha1-j5A0HmilPMySh4jaz80Rs265t44=", - "dev": true, "requires": { "core-util-is": "~1.0.0", "inherits": "~2.0.1", @@ -118,7 +104,6 @@ "version": "0.1.0", "resolved": "https://registry.npmjs.org/sketch-constructor/-/sketch-constructor-0.1.0.tgz", "integrity": "sha512-x7jd0Dlj8pbdJ8lrEEak20K5g0s/s8s6BGiGUXrgdPi43CnLaDY5kH2Dwyy7v+Nb2xLk8N5kRATT6by9oYZpUw==", - "dev": true, "requires": { "fs-extra": "^7.0.1", "jszip": "^3.1.5", @@ -129,32 +114,27 @@ "string_decoder": { "version": "0.10.31", "resolved": "https://registry.npmjs.org/string_decoder/-/string_decoder-0.10.31.tgz", - "integrity": "sha1-YuIDvEF2bGwoyfyEMB2rHFMQ+pQ=", - "dev": true + "integrity": "sha1-YuIDvEF2bGwoyfyEMB2rHFMQ+pQ=" }, "tinycolor2": { "version": "1.4.1", "resolved": "https://registry.npmjs.org/tinycolor2/-/tinycolor2-1.4.1.tgz", - "integrity": "sha1-9PrTM0R7wLB9TcjpIJ2POaisd+g=", - "dev": true + "integrity": "sha1-9PrTM0R7wLB9TcjpIJ2POaisd+g=" }, "universalify": { "version": "0.1.2", "resolved": "https://registry.npmjs.org/universalify/-/universalify-0.1.2.tgz", - "integrity": "sha512-rBJeI5CXAlmy1pV+617WB9J63U6XcazHHF2f2dbJix4XzpUF0RS3Zbj0FGIOCAva5P/d/GBOYaACQ1w+0azUkg==", - "dev": true + "integrity": "sha512-rBJeI5CXAlmy1pV+617WB9J63U6XcazHHF2f2dbJix4XzpUF0RS3Zbj0FGIOCAva5P/d/GBOYaACQ1w+0azUkg==" }, "util-deprecate": { "version": "1.0.2", "resolved": "https://registry.npmjs.org/util-deprecate/-/util-deprecate-1.0.2.tgz", - "integrity": "sha1-RQ1Nyfpw3nMnYvvS1KKJgUGaDM8=", - "dev": true + "integrity": "sha1-RQ1Nyfpw3nMnYvvS1KKJgUGaDM8=" }, "uuid-v4": { "version": "0.1.0", "resolved": "https://registry.npmjs.org/uuid-v4/-/uuid-v4-0.1.0.tgz", - "integrity": "sha1-YtezEEBvbOz+oVKMafHo4LzsWjo=", - "dev": true + "integrity": "sha1-YtezEEBvbOz+oVKMafHo4LzsWjo=" } } } diff --git a/index.d.ts b/index.d.ts new file mode 100644 index 0000000..0e1c231 --- /dev/null +++ b/index.d.ts @@ -0,0 +1,2 @@ +export * from './models'; +export * from './utils'; diff --git a/models/Artboard/index.d.ts b/models/Artboard/index.d.ts new file mode 100644 index 0000000..9e7cb65 --- /dev/null +++ b/models/Artboard/index.d.ts @@ -0,0 +1,20 @@ +import Color from '../Color'; +import Group from '../Group'; +import RulerData from '../RulerData'; + +declare class Artboard extends Group { + _class: 'artboard'; + shouldBreakMaskChain: boolean; + backgroundColor: Color; + hasBackgroundColor: boolean; + horizontalRulerData: RulerData; + verticalRulerData: RulerData; + includeBackgroundColorInExport: boolean; + includeInCloudUpload: boolean; + isFlowHome: boolean; + resizesContent: boolean; + + constructor(args?: any, json?: any); +} + +export = Artboard; diff --git a/models/AttributedString/index.d.ts b/models/AttributedString/index.d.ts new file mode 100644 index 0000000..5b14982 --- /dev/null +++ b/models/AttributedString/index.d.ts @@ -0,0 +1,11 @@ +import StringAttribute from '../StringAttribute'; + +declare class AttributedString { + _class: 'attributedString'; + string: string; + attributes: StringAttribute[]; + + constructor(args?: any, json?: any); +} + +export = AttributedString; diff --git a/models/Border/index.d.ts b/models/Border/index.d.ts new file mode 100644 index 0000000..646e5eb --- /dev/null +++ b/models/Border/index.d.ts @@ -0,0 +1,20 @@ +import Color from '../Color'; + +declare class Border { + static Position: { + Inside: 1; + Center: 0; + Outside: 2; + }; + + constructor(args?: any, json?: any); + + _class: 'border'; + isEnabled: boolean; + color: Color; + fillType: number; + position: 0 | 1 | 2; + thickness: number; +} + +export = Border; diff --git a/models/BorderOptions/index.d.ts b/models/BorderOptions/index.d.ts new file mode 100644 index 0000000..098a688 --- /dev/null +++ b/models/BorderOptions/index.d.ts @@ -0,0 +1,23 @@ +declare class BorderOptions { + static LineCapStyle: { + butt: 0; + round: 1; + projecting: 2; + }; + + static LineJoinStyle: { + miter: 0; + round: 1; + bevel: 2; + }; + + constructor(args?: any, json?: any); + + _class: 'borderOptions'; + isEnabled: boolean; + dashPattern: number[]; + lineCapStyle: 0 | 1 | 2; + lineJoinStyle: 0 | 1 | 2; +} + +export = BorderOptions; diff --git a/models/Color/index.d.ts b/models/Color/index.d.ts new file mode 100644 index 0000000..454b90b --- /dev/null +++ b/models/Color/index.d.ts @@ -0,0 +1,17 @@ +import TinyColor from 'tinycolor2'; + +declare class Color { + _class: 'color'; + alpha: number; + blue: number; + green: number; + red: number; + + constructor(args?: any, json?: any); + + set(tinyColor: TinyColor.Instance): Color; + + _getTinyColor(): TinyColor.Instance; +} + +export = Color; diff --git a/models/CurvePoint/index.d.ts b/models/CurvePoint/index.d.ts new file mode 100644 index 0000000..45944be --- /dev/null +++ b/models/CurvePoint/index.d.ts @@ -0,0 +1,14 @@ +declare class CurvePoint { + _class: 'curvePoint'; + cornerRadius: number; + curveFrom: string; + curveTo: string; + hasCurveFrom: boolean; + hasCurveTo: boolean; + point: string; + + constructor(args?: any, json?: any); + +} + +export = CurvePoint; diff --git a/models/Document/index.d.ts b/models/Document/index.d.ts new file mode 100644 index 0000000..6be7fe2 --- /dev/null +++ b/models/Document/index.d.ts @@ -0,0 +1,52 @@ +import Color from '../Color'; +import Page from '../Page'; +import SharedStyle from '../SharedStyle'; + +declare class Document { + _class: 'document'; + do_objectID: string; + assets: { + _class: 'assetCollection'; + colors: Color[]; + gradients: any[]; // TODO + imageCollections: { + _class: 'imageCollection'; + images: any; // TODO + }, + images: any[]; // TODO + }; + colorSpace: number; + currentPageIndex: number; + foreignLayerStyles: SharedStyle[]; + foreignSymbols: any[]; // TODO + foreignTextStyles: SharedStyle[]; + layerStyles: { + _class: 'sharedStyleContainer'; + objects: SharedStyle[]; + }; + layerSymbols: { + _class: 'symbolContainer'; + objects: any[]; // TODO + }; + layerTextStyles: { + _class: 'sharedTextStyleContainer'; + objects: SharedStyle[]; + }; + pages: Page[]; + + constructor(args?: any, json?: any); + + getLayerStyles(): SharedStyle[]; + + getLayerStyle(name: string): SharedStyle | undefined; + + addLayerStyle(style: SharedStyle): Document; + + getTextStyles(): SharedStyle[]; + + addTextStyle(style: SharedStyle): Document; + + addPage(pageID: string): Document; +} + +export = Document; diff --git a/models/ExportFormat/index.d.ts b/models/ExportFormat/index.d.ts new file mode 100644 index 0000000..fb4f181 --- /dev/null +++ b/models/ExportFormat/index.d.ts @@ -0,0 +1,13 @@ +declare class ExportFormat { + _class: 'exportFormat'; + absoluteSize: number; + fileFormat: string; + name: string; + nameScheme: number; + scale: number; + visibleScaleType: number; + + constructor(args?: any, json?: any); +} + +export = ExportFormat; diff --git a/models/ExportOptions/index.d.ts b/models/ExportOptions/index.d.ts new file mode 100644 index 0000000..1aee565 --- /dev/null +++ b/models/ExportOptions/index.d.ts @@ -0,0 +1,12 @@ +import ExportFormat from '../ExportFormat'; + +declare class ExportOptions { + _class: 'exportOptions'; + exportFormats: ExportFormat[]; + includedLayerIds: string[]; + layerOptions: number; + shouldTrim: boolean; + constructor(args?: any, json?: any); +} + +export = ExportOptions; diff --git a/models/Fill/index.d.ts b/models/Fill/index.d.ts new file mode 100644 index 0000000..eccdb78 --- /dev/null +++ b/models/Fill/index.d.ts @@ -0,0 +1,25 @@ +import Color from '../Color'; +import Gradient from '../Gradient'; + +declare class Fill { + static FillType: { + Color: 0, + Gradient: 1, + Pattrern: 4, + Noise: 5, + }; + + _class: 'fill'; + isEnabled: boolean; + color: Color; + fillType: 0 | 1 | 4 | 5; + noiseIndex: number; + noiseIntensity: number; + patternFillType: number; + patternTileScale: number; + gradient: Gradient; + + constructor(args?: any, json?: any); +} + +export = Fill; diff --git a/models/Gradient/index.d.ts b/models/Gradient/index.d.ts new file mode 100644 index 0000000..04f26c7 --- /dev/null +++ b/models/Gradient/index.d.ts @@ -0,0 +1,26 @@ +import Color from '../Color'; + +declare class Gradient { + static GradientStop: { + _class: 'gradientStop'; + color: Color; + position: number; + } + + static GradientType: { + Linear: 0; + Radial: 1; + Angular: 2; + } + + _class: 'gradient'; + elipseLength: number; + from: string; + to: string; + gradientType: number; + stops: Array; + + constructor(args?: any, json?: any); +} + +export = Gradient; diff --git a/models/Group/index.d.ts b/models/Group/index.d.ts new file mode 100644 index 0000000..e4638d8 --- /dev/null +++ b/models/Group/index.d.ts @@ -0,0 +1,11 @@ +import Layer from '../Layer'; + +declare class Group extends Layer { + _class: string; + layerListExpandedType: number; + resizingConstraint: number; + hasClickThrough: boolean; + constructor(args?: any, json?: any); +} + +export = Group; diff --git a/models/Layer/index.d.ts b/models/Layer/index.d.ts new file mode 100644 index 0000000..209b385 --- /dev/null +++ b/models/Layer/index.d.ts @@ -0,0 +1,40 @@ +import ExportOptions from '../ExportOptions'; +import Group from '../Group'; +import Rect from '../Rect'; +import SharedStyle from '../SharedStyle'; +import Style from '../Style'; + +declare class Layer { + _class: string; + do_objectID: string; + booleanOperation: number; + exportOptions: ExportOptions; + frame: Rect; + isFixedToViewport: boolean; + isFlippedHorizontal: boolean; + isFlippedVertical: boolean; + isLocked: boolean; + isVisible: boolean; + layerListExpandedType: number; + name: string; + nameIsFixed: boolean; + resizingConstraint: number; + resizingType: number; + rotation: number; + shouldBreakMaskChain: boolean; + style: Style; + + constructor(args?: any, json?: any); + + addLayer(layer: Layer): Layer; + + setSharedStyle(style: SharedStyle): void; + + getGroups(): Group[]; + + getLayers(predicate?: string | RegExp): Layer[]; + + getID(): string; +} + +export = Layer; diff --git a/models/Meta/index.d.ts b/models/Meta/index.d.ts new file mode 100644 index 0000000..f185ba5 --- /dev/null +++ b/models/Meta/index.d.ts @@ -0,0 +1,33 @@ +import Artboard from '../Artboard'; +import Page from '../Page'; + +declare class Meta { + commit: string; + pagesAndArtboards: any; + version: number; + fonts: any[]; // TODO + compatibilityVersion: number; + app: string; + autosaved: number; + variant: string; + created: { + commit: string; + appVersion: string; + build: number; + app: string; + compatibilityVersion: number; + version: number; + variant: string; + }; + saveHistory: string[]; + appVersion: string; + build: string; + + constructor(args?: any, json?: any); + + addPage(page: Page): void; + + addArtboard(pageID: string, artboard: Artboard): void; +} + +export = Meta; diff --git a/models/Oval/index.d.ts b/models/Oval/index.d.ts new file mode 100644 index 0000000..9fc9969 --- /dev/null +++ b/models/Oval/index.d.ts @@ -0,0 +1,13 @@ +import Layer from '../Layer'; +import CurvePoint from '../CurvePoint'; + +declare class Oval extends Layer { + _class: 'oval'; + edited: boolean; + isClosed: boolean; + pointRadiusBehaviour: number; + points: CurvePoint[]; + constructor(args?: any, json?: any); +} + +export = Oval; diff --git a/models/Page/index.d.ts b/models/Page/index.d.ts new file mode 100644 index 0000000..21b7f62 --- /dev/null +++ b/models/Page/index.d.ts @@ -0,0 +1,18 @@ +import Artboard from '../Artboard'; +import Group from '../Group'; + +declare class Page extends Group { + _class: 'page'; + + constructor(args?: any, json?: any); + + getID(): string; + + getArtboards(predicate?: string | RegExp): Artboard[]; + + getArtboard(name: string): Artboard | undefined; + + addArtboard(artboard: Artboard): Page; +} + +export = Page; diff --git a/models/Rect/index.d.ts b/models/Rect/index.d.ts new file mode 100644 index 0000000..2bc77d2 --- /dev/null +++ b/models/Rect/index.d.ts @@ -0,0 +1,11 @@ +declare class Rect { + _class: 'rect'; + constrainProportions: boolean; + height: number; + width: number; + x: number; + y: number; + constructor(args?: any, json?: any); +} + +export = Rect; diff --git a/models/Rectangle/index.d.ts b/models/Rectangle/index.d.ts new file mode 100644 index 0000000..659ab05 --- /dev/null +++ b/models/Rectangle/index.d.ts @@ -0,0 +1,15 @@ +import Layer from '../Layer'; +import CurvePoint from '../CurvePoint'; + +declare class Rectangle extends Layer { + _class: 'rectangle'; + edited: boolean; + isClosed: boolean; + pointRadoisBehaviour: number; + points: CurvePoint[]; + fixedRadius: number; + hasConvertedToNewRoundCorners: boolean; + constructor(args?: any, json?: any); +} + +export = Rectangle; diff --git a/models/RulerData/index.d.ts b/models/RulerData/index.d.ts new file mode 100644 index 0000000..8ddaa50 --- /dev/null +++ b/models/RulerData/index.d.ts @@ -0,0 +1,9 @@ +declare class RulerData { + _class: 'rulerData'; + base: number; + guides: any[]; // TODO + + constructor(args?: any, json?: any); +} + +export = RulerData; \ No newline at end of file diff --git a/models/Shadow/index.d.ts b/models/Shadow/index.d.ts new file mode 100644 index 0000000..23e3cc6 --- /dev/null +++ b/models/Shadow/index.d.ts @@ -0,0 +1,20 @@ +import Color from '../Color'; + +declare class Shadow { + _class: 'shadow'; + isEnabled: boolean; + blurRadius: number; + color: Color; + contextSettings: { + _class: 'graphicsContextSettings'; + blendMode: number; + opacity: number; + }; + offsetX: number; + offsetY: number; + spread: number; + + constructor(args?: any, json?: any); +} + +export = Shadow; diff --git a/models/ShapeGroup/index.d.ts b/models/ShapeGroup/index.d.ts new file mode 100644 index 0000000..047b270 --- /dev/null +++ b/models/ShapeGroup/index.d.ts @@ -0,0 +1,15 @@ +import Layer from '../Layer'; + +declare class ShapeGroup extends Layer { + static Rectangle(args: any): ShapeGroup; + + static Oval(args: any): ShapeGroup; + + _class: 'shapeGroup'; + layerListExpandedType: number; + clippingMaskMode: number; + hasClippingMask: boolean; + windingRule: number; + + constructor(args?: any, json?: any); +} \ No newline at end of file diff --git a/models/SharedStyle/index.d.ts b/models/SharedStyle/index.d.ts new file mode 100644 index 0000000..6588090 --- /dev/null +++ b/models/SharedStyle/index.d.ts @@ -0,0 +1,16 @@ +import Style from '../Style'; + +declare class SharedStyle { + _class: 'sharedStyle'; + name: string; + do_objectID: string; + value: Style; + + static LayerStyle(args: any): SharedStyle; + + static TextStyle(args: any): SharedStyle; + + constructor(args?: any, json?: any); +} + +export = SharedStyle; diff --git a/models/Sketch/index.d.ts b/models/Sketch/index.d.ts new file mode 100644 index 0000000..f5c2ebd --- /dev/null +++ b/models/Sketch/index.d.ts @@ -0,0 +1,41 @@ +import fs from 'fs'; +import JSZip from 'jszip'; +import Meta from '../Meta'; +import User from '../User'; +import Document from '../Document'; +import Page from '../Page'; +import SharedStyle from '../SharedStyle'; + +declare class Sketch { + static fromFile(path: string): Promise; + + document: Document; + meta: Meta; + user: User; + pages: Page[]; + zip: JSZip; + + constructor(args?: any); + + getPages(predicate?: string | RegExp): Page[]; + + getPage(name: string): Page | undefined; + + getLayerStyles(): SharedStyle[]; + + getLayerStyle(name: string): SharedStyle | undefined; + + addLayerStyle(style: SharedStyle): void; + + addTextStyle(style: SharedStyle): void; + + getTextStyles(): SharedStyle[]; + + addPage(page: any, args?: any): void; + + addArtboard(pageID: string, artboard: any): void; + + build(output: fs.PathLike | number): Promise; +} + +export = Sketch; diff --git a/models/StringAttribute/index.d.ts b/models/StringAttribute/index.d.ts new file mode 100644 index 0000000..ade549f --- /dev/null +++ b/models/StringAttribute/index.d.ts @@ -0,0 +1,28 @@ +import Color from '../Color'; +// import { textAlignmentMap, verticalAlignmentMap } from '../../utils/maps'; + +declare class StringAttribute { + _class: 'stringAttribute'; + location: number; + attributes: { + MSAttributedStringTextTransformAttribute: number; + MSAttributedStringFontAttribute: { + _class: 'fontDescriptor'; + attributes: { + name: string; + size: number; + }; + }; + MSAttributedStringColorAttribute: Color; + textStyleVerticalAlignmentKey: number; + underlineStyle: number; + strikethroughStyle: number; + paragraphStyle: { + _class: 'paragraphStyle'; + alignment: number; + }; + }; + constructor(args?: any, json?: any); +} + +export = StringAttribute; diff --git a/models/Style/index.d.ts b/models/Style/index.d.ts new file mode 100644 index 0000000..7727285 --- /dev/null +++ b/models/Style/index.d.ts @@ -0,0 +1,62 @@ +import TextStyle from '../TextStyle'; +import Fill from '../Fill'; +import Border from '../Border'; +import Shadow from '../Shadow'; + +declare class Style { + static MarkerType: { + none: 0; + openArrow: 1; + filledArrow: 2; + line: 3; + openCircle: 4; + filledCircle: 5; + openSquare: 6; + filledSquare: 7; + }; + + static WindingRule: {[key: string]: number}; // TODO + + static BlendMode: { + Normal: 0; + Darken: 1; + Multiply: 2; + ColorBurn: 3; + Lighten: 4; + Screen: 5; + ColorDodge: 6; + Overlay: 7; + SoftLight: 8; + HardLight: 9; + Difference: 10; + Exclusion: 11; + Hue: 12; + Saturation: 13; + Color: 14; + Luminosity: 15; + }; + + static LayerStyle(args?: any): Style; + + static TextStyle(args?: any): Style; + + _class: 'style'; + do_objectID: string; + startMarkerType: number; + endMarkerType: number; + miterLimit: number; + windingRule: number; + borders: Border[]; + fills: Fill[]; + shadows: Shadow[]; + textStyle: TextStyle; + contextSettings: { + _class: 'graphicsContextSettings'; + blendMode: number; + opacity: number; + }; + + constructor(args?: any, json?: any); +} + +export = Style; \ No newline at end of file diff --git a/models/SymbolInstance/index.d.ts b/models/SymbolInstance/index.d.ts new file mode 100644 index 0000000..214172e --- /dev/null +++ b/models/SymbolInstance/index.d.ts @@ -0,0 +1,10 @@ +import Layer from '../Layer'; + +declare class SymbolInstance extends Layer { + symbolID: string; + overrideValues: any[]; + + constructor(args?: any, json?: any); +} + +export = SymbolInstance; diff --git a/models/SymbolMaster/index.d.ts b/models/SymbolMaster/index.d.ts new file mode 100644 index 0000000..64fab93 --- /dev/null +++ b/models/SymbolMaster/index.d.ts @@ -0,0 +1,10 @@ +import Artboard from '../Artboard'; + +declare class SymbolMaster extends Artboard { + symbolID: string; + changeIdentifier: number; + + constructor(args?: any, json?: any); +} + +export = SymbolMaster; diff --git a/models/Text/index.d.ts b/models/Text/index.d.ts new file mode 100644 index 0000000..f0e34e7 --- /dev/null +++ b/models/Text/index.d.ts @@ -0,0 +1,15 @@ +import Layer from '../Layer'; +import AttributedString from '../AttributedString'; + +declare class Text extends Layer { + automaticallyDrawOnUnderlyingPath: boolean; + dontSynchroniseWithSymbol: boolean; + attributedString: AttributedString; + glyphBounds: string; + lineSpacingBehaviour: number; + textBehaviour: number; + + constructor(args?: any, json?: any); +} + +export = Text; diff --git a/models/TextStyle/index.d.ts b/models/TextStyle/index.d.ts new file mode 100644 index 0000000..d581dcf --- /dev/null +++ b/models/TextStyle/index.d.ts @@ -0,0 +1,34 @@ +import Color from '../Color'; +// import { textAlignmentMap, verticalAlignmentMap } from '../../utils/maps'; + +declare class TextStyle { + _class: 'textStyle'; + encodedAttributes: { + MSAttributedStringFontAttribute: { + _class: 'fontDescriptor'; + attributes: { + name: string; + size: number; + }; + }; + MSAttributedStringColorAttribute: Color; + textStyleVerticalAlignmentKey: number; + underlineStyle: number; + strikethroughStyle: number; + paragraphStyle: { + _class: 'paragraphStyle'; + alignment: number; + }; + }; + verticalAlignment: number; + + constructor(args?: any, json?: any); + + getColor(): Color; + + getFontSize(): number; + + getFontName(): string; +} + +export = TextStyle; diff --git a/models/User/index.d.ts b/models/User/index.d.ts new file mode 100644 index 0000000..6145d77 --- /dev/null +++ b/models/User/index.d.ts @@ -0,0 +1,12 @@ +declare class User { + document: { + pageListHeight: string; + }; + + constructor(args?: any, json?: any); + + addPage(pageID: string, opts: { scrollOrigin: string, zoomValue: number }): User; + +} + +export = User; diff --git a/models/index.d.ts b/models/index.d.ts new file mode 100644 index 0000000..72d2b71 --- /dev/null +++ b/models/index.d.ts @@ -0,0 +1,53 @@ +import Artboard from './Artboard'; +import Group from './Group'; +import Border from './Border'; +import BorderOptions from './BorderOptions'; +import Color from './Color'; +import CurvePoint from './CurvePoint'; +import Document from './Document'; +import ExportFormat from './ExportFormat'; +import ExportOptions from './ExportOptions'; +import Fill from './Fill'; +import Gradient from './Gradient'; +import Meta from './Meta'; +import Oval from './Oval'; +import Page from './Page'; +import Rect from './Rect'; +import Rectangle from './Rectangle'; +import RulerData from './RulerData'; +import Shadow from './Shadow'; +import ShapeGroup from './ShapeGroup'; +import SharedStyle from './SharedStyle'; +import Sketch from './Sketch'; +import Style from './Style'; +import Text from './Text'; +import TextStyle from './TextStyle'; +import User from './User'; + +export { + Artboard, + Group, + Border, + BorderOptions, + Color, + CurvePoint, + Document, + ExportFormat, + ExportOptions, + Fill, + Gradient, + Meta, + Oval, + Page, + Rect, + Rectangle, + RulerData, + Shadow, + ShapeGroup, + SharedStyle, + Sketch, + Style, + Text, + TextStyle, + User, +}; diff --git a/package-lock.json b/package-lock.json index a580c53..d78b288 100644 --- a/package-lock.json +++ b/package-lock.json @@ -911,6 +911,24 @@ } } }, + "@types/jszip": { + "version": "3.1.6", + "resolved": "http://bnpm.byted.org/@types/jszip/download/@types/jszip-3.1.6.tgz", + "integrity": "sha1-BRJXSis18xlLQXacVuSzUGXmcAA=", + "requires": { + "@types/node": "*" + } + }, + "@types/node": { + "version": "12.0.4", + "resolved": "http://bnpm.byted.org/@types/node/download/@types/node-12.0.4.tgz", + "integrity": "sha1-RoMhgxFckEQQwnXjTPlAOZKZnDI=" + }, + "@types/tinycolor2": { + "version": "1.4.2", + "resolved": "http://bnpm.byted.org/@types/tinycolor2/download/@types/tinycolor2-1.4.2.tgz", + "integrity": "sha1-chylxdGimItKiG41wv/Fc1tq+98=" + }, "JSONStream": { "version": "1.3.5", "resolved": "https://registry.npmjs.org/JSONStream/-/JSONStream-1.3.5.tgz", @@ -15668,6 +15686,12 @@ "integrity": "sha1-hnrHTjhkGHsdPUfZlqeOxciDB3c=", "dev": true }, + "typescript": { + "version": "3.5.1", + "resolved": "http://bnpm.byted.org/typescript/download/typescript-3.5.1.tgz", + "integrity": "sha1-unKmpgCyFYE5xd2IUPcA4jFGQgI=", + "dev": true + }, "typical": { "version": "2.6.1", "resolved": "https://registry.npmjs.org/typical/-/typical-2.6.1.tgz", diff --git a/package.json b/package.json index df61178..cc5ddfa 100644 --- a/package.json +++ b/package.json @@ -3,6 +3,7 @@ "version": "0.0.0-development", "description": "Read/write/manipulate Sketch files in Node without Sketch plugins!", "main": "index.js", + "types": "index.d.ts", "files": [ "models", "utils", @@ -13,7 +14,8 @@ ], "scripts": { "lint": "eslint index.js models/**/*.js utils/**/*.js", - "test": "npm run lint && jest --runInBand", + "type-check": "tsc --noEmit", + "test": "npm run lint && npm run type-check && jest --runInBand", "commit": "git-cz", "preversion": "npm test && npm run docs:build", "release": "git add . && standard-version -a", @@ -60,6 +62,9 @@ ], "homepage": "https://github.com/amzn/sketch-constructor#readme", "dependencies": { + "@types/jszip": "^3.1.6", + "@types/node": "^12.0.4", + "@types/tinycolor2": "^1.4.2", "fs-extra": "^7.0.1", "jszip": "^3.1.5", "tinycolor2": "^1.4.1", @@ -83,8 +88,9 @@ "lint-staged": "^8.1.0", "minami": "^1.2.3", "prettier": "^1.16.1", + "semantic-release": "^15.13.3", "standard-version": "^4.4.0", - "semantic-release": "^15.13.3" + "typescript": "^3.5.1" }, "config": { "commitizen": { diff --git a/tsconfig.json b/tsconfig.json new file mode 100644 index 0000000..ebe06c5 --- /dev/null +++ b/tsconfig.json @@ -0,0 +1,60 @@ +{ + "exclude": ["node_modules"], + "compilerOptions": { + /* Basic Options */ + "target": "es5", /* Specify ECMAScript target version: 'ES3' (default), 'ES5', 'ES2015', 'ES2016', 'ES2017','ES2018' or 'ESNEXT'. */ + "module": "commonjs", /* Specify module code generation: 'none', 'commonjs', 'amd', 'system', 'umd', 'es2015', or 'ESNext'. */ + "lib": ["es2015", "dom"], /* Specify library files to be included in the compilation. */ + // "allowJs": true, /* Allow javascript files to be compiled. */ + // "checkJs": true, /* Report errors in .js files. */ + // "jsx": "preserve", /* Specify JSX code generation: 'preserve', 'react-native', or 'react'. */ + "declaration": true, /* Generates corresponding '.d.ts' file. */ + // "declarationMap": true, /* Generates a sourcemap for each corresponding '.d.ts' file. */ + // "sourceMap": true, /* Generates corresponding '.map' file. */ + // "outFile": "./", /* Concatenate and emit output to single file. */ + // "outDir": "./", /* Redirect output structure to the directory. */ + // "rootDir": "./", /* Specify the root directory of input files. Use to control the output directory structure with --outDir. */ + // "composite": true, /* Enable project compilation */ + // "removeComments": true, /* Do not emit comments to output. */ + // "noEmit": true, /* Do not emit outputs. */ + // "importHelpers": true, /* Import emit helpers from 'tslib'. */ + // "downlevelIteration": true, /* Provide full support for iterables in 'for-of', spread, and destructuring when targeting 'ES5' or 'ES3'. */ + // "isolatedModules": true, /* Transpile each file as a separate module (similar to 'ts.transpileModule'). */ + + /* Strict Type-Checking Options */ + "strict": true, /* Enable all strict type-checking options. */ + // "noImplicitAny": true, /* Raise error on expressions and declarations with an implied 'any' type. */ + // "strictNullChecks": true, /* Enable strict null checks. */ + // "strictFunctionTypes": true, /* Enable strict checking of function types. */ + // "strictPropertyInitialization": true, /* Enable strict checking of property initialization in classes. */ + // "noImplicitThis": true, /* Raise error on 'this' expressions with an implied 'any' type. */ + // "alwaysStrict": true, /* Parse in strict mode and emit "use strict" for each source file. */ + + /* Additional Checks */ + // "noUnusedLocals": true, /* Report errors on unused locals. */ + // "noUnusedParameters": true, /* Report errors on unused parameters. */ + // "noImplicitReturns": true, /* Report error when not all code paths in function return a value. */ + // "noFallthroughCasesInSwitch": true, /* Report errors for fallthrough cases in switch statement. */ + + /* Module Resolution Options */ + // "moduleResolution": "node", /* Specify module resolution strategy: 'node' (Node.js) or 'classic' (TypeScript pre-1.6). */ + // "baseUrl": "./", /* Base directory to resolve non-absolute module names. */ + // "paths": {}, /* A series of entries which re-map imports to lookup locations relative to the 'baseUrl'. */ + // "rootDirs": [], /* List of root folders whose combined content represents the structure of the project at runtime. */ + // "typeRoots": [], /* List of folders to include type definitions from. */ + // "types": [], /* Type declaration files to be included in compilation. */ + // "allowSyntheticDefaultImports": true, /* Allow default imports from modules with no default export. This does not affect code emit, just typechecking. */ + "esModuleInterop": true /* Enables emit interoperability between CommonJS and ES Modules via creation of namespace objects for all imports. Implies 'allowSyntheticDefaultImports'. */ + // "preserveSymlinks": true, /* Do not resolve the real path of symlinks. */ + + /* Source Map Options */ + // "sourceRoot": "", /* Specify the location where debugger should locate TypeScript files instead of source locations. */ + // "mapRoot": "", /* Specify the location where debugger should locate map files instead of generated locations. */ + // "inlineSourceMap": true, /* Emit a single file with source maps instead of having a separate file. */ + // "inlineSources": true, /* Emit the source alongside the sourcemaps within a single file; requires '--inlineSourceMap' or '--sourceMap' to be set. */ + + /* Experimental Options */ + // "experimentalDecorators": true, /* Enables experimental support for ES7 decorators. */ + // "emitDecoratorMetadata": true, /* Enables experimental support for emitting type metadata for decorators. */ + } +} diff --git a/utils/index.d.ts b/utils/index.d.ts new file mode 100644 index 0000000..da5c989 --- /dev/null +++ b/utils/index.d.ts @@ -0,0 +1,23 @@ +import Layer from "../models/Layer"; + +declare const layerToClass: (layer: any) => Layer; +declare const maps: { + textAlignmentMap: { + left: 0, + right: 1, + center: 2, + justify: 3, + }; + verticalAlignmentMap: { + top: 0, + bottom: 1, + center: 2, + }; +}; +declare const stackLayers: (layers: Layer[], gutter?: number) => Layer[]; + +export { + layerToClass, + maps, + stackLayers, +};