Skip to content

Commit b4eb5a3

Browse files
committed
🐛 fix: Fix lint and type
1 parent 9a8cb9d commit b4eb5a3

File tree

14 files changed

+1024
-232
lines changed

14 files changed

+1024
-232
lines changed

.webstorm/.run/测试 Modal 类型.run.xml

Lines changed: 728 additions & 0 deletions
Large diffs are not rendered by default.

src/model/Base/Frame.ts

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,6 @@
11
import SketchFormat from '@sketch-hq/sketch-file-format-ts';
2+
import { FrameInitParams } from 'html2sketch/model/type';
23

3-
export interface FrameInitParams extends Partial<FrameType> {}
4-
5-
export interface FrameType {
6-
x: number;
7-
y: number;
8-
width: number;
9-
height: number;
10-
}
114
/**
125
* @class
136
* Frame 类型

src/model/Document/Page.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import SketchFormat from '@sketch-hq/sketch-file-format-ts';
2-
import BaseLayer, { BaseLayerParams } from '../Base/BaseLayer';
2+
import BaseLayer from '../Base/BaseLayer';
33
import { defaultRuleData, defaultExportOptions } from '../utils';
4+
import { BaseLayerParams } from '../type';
45

56
interface PageInitParams extends Pick<BaseLayerParams, 'height' | 'width'> {}
67

src/model/Layer/Artboard.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
import SketchFormat from '@sketch-hq/sketch-file-format-ts';
22

3-
import BaseLayer, { BaseLayerParams } from '../Base/BaseLayer';
3+
import BaseLayer from '../Base/BaseLayer';
44
import { defaultRuleData, defaultExportOptions } from '../utils';
55
import Color from '../Style/Color';
6+
import { BaseLayerParams } from '../type';
67

78
/**
89
* 画板对象

src/model/Layer/Bitmap.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
import SketchFormat from '@sketch-hq/sketch-file-format-ts';
2-
import BaseLayer, { BaseLayerParams } from '../Base/BaseLayer';
2+
import BaseLayer from '../Base/BaseLayer';
33
import { defaultExportOptions } from '../utils';
44
import { getBase64ImageString } from '../../utils/url';
55
import { uuid } from '../../utils/utils';
6+
import { BaseLayerParams } from '../type';
67

78
interface BitmapInitParams extends BaseLayerParams {
89
url: string;

src/model/Layer/ShapeGroup.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
import SketchFormat from '@sketch-hq/sketch-file-format-ts';
2-
import BaseLayer, { BaseLayerParams } from '../Base/BaseLayer';
2+
import BaseLayer from '../Base/BaseLayer';
33
import { defaultExportOptions } from '../utils';
44
import ShapePath from './ShapePath';
5+
import { BaseLayerParams } from '../type';
56

67
class ShapeGroup extends BaseLayer {
78
constructor(params?: BaseLayerParams) {

src/model/Layer/Svg.ts

Lines changed: 124 additions & 94 deletions
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,20 @@ import { SVGPathData } from 'svg-pathdata';
55
import BaseLayer from '../Base/BaseLayer';
66
import ShapePath from './ShapePath';
77
import ShapeGroup from './ShapeGroup';
8-
import { FrameType } from '../Base/Frame';
98

109
import { getUseReplacement, inlineStyles } from '../../utils/svg';
1110
import { defaultExportOptions } from '../utils';
1211
import { getGroupLayout } from '../../utils/layout';
1312
import Style from '../Style/Style';
14-
import { ShapeGroupType, SvgShape, BaseLayerParams, SvgEllipse } from '../type';
13+
import {
14+
ShapeGroupType,
15+
BaseLayerParams,
16+
FrameType,
17+
// SvgEllipse,
18+
// BaseSvgShape,
19+
// AnySvgShape,
20+
// SvgPath,
21+
} from '../type';
1522

1623
interface SvgInitParams extends Partial<BaseLayerParams> {
1724
svgString: string;
@@ -39,7 +46,7 @@ class Svg extends BaseLayer {
3946
// ------ 将 Svg 的子节点转换成内部格式 ------ //
4047

4148
// @ts-ignore
42-
let shapes: SvgShape[] = children
49+
let shapes: { path: string; style?: string }[] = children
4350

4451
// eslint-disable-next-line array-callback-return
4552
.map((node) => {
@@ -114,7 +121,7 @@ class Svg extends BaseLayer {
114121
*/
115122
layers: ShapeGroup[] = [];
116123

117-
shapes: SvgShape[] = [];
124+
shapes: { path: string; style?: string }[] = [];
118125

119126
/**
120127
* 原生 Svg 字符串
@@ -312,89 +319,89 @@ class Svg extends BaseLayer {
312319
* 将 svgon 解析出来的 node 转变为 svgShape
313320
* @param node
314321
*/
315-
static parseSvgsonToSvgShapes = (
316-
node?: svgson.INode,
317-
): SvgShape | SvgShape[] | undefined => {
318-
if (!node) return;
319-
const { children } = node;
320-
if (children.length > 0) {
321-
const svgShapes = children.map(Svg.parseSvgsonToSvgShape);
322-
return svgShapes.filter((s) => s) as SvgShape[];
323-
}
324-
return Svg.parseSvgsonToSvgShape(node);
325-
};
326-
327-
static parseSvgsonToSvgShape = (
328-
node: svgson.INode,
329-
): SvgShape | SvgShape[] | undefined => {
330-
const { children, attributes, name, type, value } = node;
331-
332-
let layers: SvgShape[] = [];
333-
334-
switch (name) {
335-
// 入口
336-
case 'svg':
337-
if (children.length > 0) {
338-
const svgShapes = children.map(Svg.parseSvgsonToSvgShape);
339-
layers = svgShapes.filter((s) => s) as SvgShape[];
340-
}
341-
return layers;
342-
// 编组
343-
case 'g':
344-
if (children.length > 0) {
345-
const svgShapes = children.map(Svg.parseSvgsonToSvgShape);
346-
layers = svgShapes.filter((s) => s) as SvgShape[];
347-
}
348-
return {
349-
type: 'group',
350-
layers,
351-
path: '',
352-
style: attributes.style,
353-
};
354-
case 'defs':
355-
return {};
356-
357-
// path
358-
case 'path':
359-
return {
360-
path: attributes.d,
361-
style: attributes.style,
362-
layers,
363-
};
364-
// 圆形
365-
case 'ellipse':
366-
return {
367-
style: attributes.style,
368-
};
369-
370-
// 两者是无关紧要的信息
371-
case 'title':
372-
case 'desc':
373-
default:
374-
}
375-
};
322+
// static parseSvgsonToSvgShapes = (
323+
// node?: svgson.INode,
324+
// ): BaseSvgShape | BaseSvgShape[] | undefined => {
325+
// if (!node) return;
326+
// const { children } = node;
327+
// if (children.length > 0) {
328+
// const svgShapes = children.map(Svg.parseSvgsonToSvgShape);
329+
// return svgShapes.filter((s) => s) as BaseSvgShape[];
330+
// }
331+
// return Svg.parseSvgsonToSvgShape(node);
332+
// };
333+
334+
// static parseSvgsonToSvgShape = (
335+
// node: svgson.INode,
336+
// ): AnySvgShape | AnySvgShape[] | undefined => {
337+
// const { children, attributes, name } = node;
338+
//
339+
// let layers: BaseSvgShape[] = [];
340+
//
341+
// switch (name) {
342+
// // 入口
343+
// case 'svg':
344+
// if (children.length > 0) {
345+
// const svgShapes = children.map(Svg.parseSvgsonToSvgShape);
346+
// layers = svgShapes.filter((s) => s) as BaseSvgShape[];
347+
// }
348+
// return layers;
349+
// // 编组
350+
// case 'g':
351+
// if (children.length > 0) {
352+
// const svgShapes = children.map(Svg.parseSvgsonToSvgShape);
353+
// layers = svgShapes.filter((s) => s) as BaseSvgShape[];
354+
// }
355+
// return {
356+
// type: 'group',
357+
// layers,
358+
// style: attributes.style,
359+
// };
360+
// case 'defs':
361+
// return {};
362+
//
363+
// // path
364+
// case 'path':
365+
// return {
366+
// path: attributes.d,
367+
// style: attributes.style,
368+
// layers,
369+
// };
370+
// // 圆形
371+
// case 'ellipse':
372+
// return {
373+
// style: attributes.style,
374+
// };
375+
//
376+
// // 两者是无关紧要的信息
377+
// case 'title':
378+
// case 'desc':
379+
// default:
380+
// }
381+
// };
376382

377383
/**
378384
* 将 svg node 转换为 svg Group 对象
379385
*/
380-
static parseGNodeToGroup = (node: svgson.INode): SvgShape | undefined => {
381-
if (node.name !== 'g') return;
382-
383-
const { attributes } = node;
384-
const { fillRule } = attributes;
385-
386-
const layers = node.children.map(Svg.parseSvgsonToSvgShapes) as SvgShape[];
387-
388-
const style = Svg.parseNodeAttrToStyle(attributes); // 解析样式
389-
390-
return {
391-
type: 'group',
392-
layers: layers || [],
393-
windingRule: Svg.normalizeWindingRule(fillRule),
394-
style,
395-
path: '',
396-
};
397-
};
386+
// static parseGNodeToGroup = (node: svgson.INode): BaseSvgShape | undefined => {
387+
// if (node.name !== 'g') return;
388+
//
389+
// const { attributes } = node;
390+
// const { fillRule } = attributes;
391+
//
392+
// const layers = node.children.map(
393+
// Svg.parseSvgsonToSvgShapes,
394+
// ) as BaseSvgShape[];
395+
//
396+
// const style = Svg.parseNodeAttrToStyle(attributes); // 解析样式
397+
//
398+
// return {
399+
// type: 'group',
400+
// layers: layers || [],
401+
// windingRule: Svg.normalizeWindingRule(fillRule),
402+
// style,
403+
// };
404+
// };
398405

399406
/**
400407
* 一致化缠绕规则参数
@@ -434,17 +441,40 @@ class Svg extends BaseLayer {
434441
* 将 ellipse 的节点解析为椭圆
435442
* @param node
436443
*/
437-
static parseNodeToEllipse = (node: svgson.INode): SvgEllipse | undefined => {
438-
if (!node || (node && node.name !== 'ellipse')) return;
439-
440-
const { cx, cy, rx, ry } = node.attributes;
441-
return {
442-
type: 'ellipse',
443-
frame: { width: rx * 2, height: ry * 2 },
444-
style: Svg.parseNodeAttrToStyle(node.attributes),
445-
layers: [],
446-
};
447-
};
444+
// static parseNodeToEllipse = (node: svgson.INode): SvgEllipse | undefined => {
445+
// if (!node || (node && node.name !== 'ellipse')) return;
446+
//
447+
// const { rx, ry } = node.attributes;
448+
// return {
449+
// type: 'ellipse',
450+
// frame: { width: rx * 2, height: ry * 2 },
451+
// style: Svg.parseNodeAttrToStyle(node.attributes),
452+
// layers: [],
453+
// };
454+
// };
455+
456+
// static parsePathToShape = (shapes: SvgPath[]) => {
457+
// const fullPathString = shapes.reduce((prev, current) => {
458+
// return { path: prev.path + current.path, layers: [] };
459+
// }).path;
460+
//
461+
// // 计算定界框的缩放尺寸
462+
// const shapeGroupFrame = Svg.getSvgPathGroupFrame(fullPathString);
463+
// const scaleShapeGroupToFrame = Svg.calcFrameScale(
464+
// shapeGroupFrame,
465+
// this.frame.toJSON(),
466+
// );
467+
// // ------ 进行统一的坐标和尺寸变换 -------- //
468+
// shapes = shapes.map((s) => ({
469+
// ...s,
470+
// path: new SVGPathData(s.path)
471+
// // 将 shapeGroup 的坐标设为 0,0
472+
// .translate(-shapeGroupFrame.x, -shapeGroupFrame.y)
473+
// // 将 shapeGroup 与给定定界框 match 变成符合外部画板的尺寸
474+
// .scale(scaleShapeGroupToFrame, scaleShapeGroupToFrame)
475+
// .encode(),
476+
// }));
477+
// };
448478
}
449479

450480
export default Svg;

src/model/Layer/SymbolInstance.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import SketchFormat from '@sketch-hq/sketch-file-format-ts';
22
import { defaultExportOptions } from '../utils';
3-
import BaseLayer, { BaseLayerParams } from '../Base/BaseLayer';
3+
import BaseLayer from '../Base/BaseLayer';
4+
import { BaseLayerParams } from '../type';
45

56
interface SymbolInstanceInitParams extends BaseLayerParams {
67
symbolID: string;

src/model/Layer/SymbolMaster.ts

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,12 @@
11
import SketchFormat from '@sketch-hq/sketch-file-format-ts';
22
import { getGroupLayout } from '../../utils/layout';
3-
import BaseLayer, { BaseLayerParams } from '../Base/BaseLayer';
3+
import BaseLayer from '../Base/BaseLayer';
44
import Color from '../Style/Color';
55
import SymbolInstance from './SymbolInstance';
66
import { uuid } from '../../utils/utils';
77
import { defaultExportOptions, defaultRuleData } from '../utils';
8-
import { AnyLayer } from '../type';
8+
import { AnyLayer, BaseLayerParams, FrameType } from '../type';
99
import { GroupLayoutType } from '../../type';
10-
import { FrameType } from '../Base/Frame';
1110

1211
/**
1312
* Sketch 的 Symbol 对象

src/model/Layer/Text.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
import SketchFormat from '@sketch-hq/sketch-file-format-ts';
2-
import BaseLayer, { BaseLayerParams } from '../Base/BaseLayer';
2+
import BaseLayer from '../Base/BaseLayer';
33
import { ResizingConstraint } from '../../utils/layout';
44
import { defaultExportOptions } from '../utils';
55
import TextStyle, { TextStyleParams } from '../Style/TextStyle';
6+
import { BaseLayerParams } from '../type';
67

78
interface TextInitParams extends BaseLayerParams {
89
text: string;

0 commit comments

Comments
 (0)