Skip to content

Commit

Permalink
chore(release): v0.5
Browse files Browse the repository at this point in the history
  • Loading branch information
bplok20010 committed Jun 5, 2021
1 parent cec6fdc commit d99c523
Show file tree
Hide file tree
Showing 28 changed files with 36,361 additions and 1 deletion.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
node_modules
dist

2 changes: 2 additions & 0 deletions .npmignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
node_modules
dist
1 change: 1 addition & 0 deletions .prettierignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
*.md
18 changes: 18 additions & 0 deletions .prettierrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
{
"arrowParens": "avoid",
"bracketSpacing": true,
"endOfLine": "auto",
"htmlWhitespaceSensitivity": "css",
"insertPragma": false,
"jsxBracketSameLine": false,
"jsxSingleQuote": false,
"printWidth": 100,
"proseWrap": "preserve",
"quoteProps": "as-needed",
"requirePragma": false,
"semi": true,
"singleQuote": false,
"tabWidth": 2,
"trailingComma": "es5",
"useTabs": false
}
162 changes: 161 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1 +1,161 @@
# refline.js
# refline.js

## Install

```cli
npm install refline.js
```

## Usage

```ts
import { RefLine } from 'refline.js'

const refLine = new RefLine({
rects: [...],
current: {...}
})

```

## Demo

[![Edit refline.js](https://codesandbox.io/static/img/play-codesandbox.svg)](https://codesandbox.io/s/reflinejs-7xnsd?fontsize=14&hidenavigation=1&theme=dark)
## Types

```ts
interface RefLineOpts<T extends Rect> {
rects: T[];
current?: T | string;
}
declare class RefLine<T extends Rect> {
protected __rects: T[];
protected _rects: T[];
protected current: null | T;
protected _dirty: boolean;
protected _vLines: LineGroup<T>[];
protected _hLines: LineGroup<T>[];
protected _vLineMap: Map<string, RefLineMeta<T>[]>;
protected _hLineMap: Map<string, RefLineMeta<T>[]>;
get rects(): T[];
get vLines(): LineGroup<T>[];
get hLines(): LineGroup<T>[];
get vLineMap(): Map<string, RefLineMeta<T>[]>;
get hLineMap(): Map<string, RefLineMeta<T>[]>;
constructor(opts?: RefLineOpts<T>);
getRectByKey(key: string | number): T | null;
getOffsetRefLineMetaList(type: LineType, offset: number): RefLineMeta<T>[];
setRects(rects: T[]): void;
protected getRect(rect: T | string): T | null;
setCurrent(current: T | string | null): void;
getCurrent(): T | null;
protected toLineMapKey<S>(v: S): string;
protected getLineMapKey(line: RefLineMeta<T>): string;
protected initRefLines(): void;
/**
* 匹配参考线
* @param type
* @param rect
* @returns
*/
matchRefLines(type: LineType): MatchedLine<T>[];
/**
* 给定offset(坐标x或y)的值,返回距离该offset的最近的两个offset(上下或左右)及距离
* @param type
* @param offset
* @returns
*/
getNearestOffsetFromOffset(type: LineType, offset: number): [[number, number] | null, [number, number] | null];
hasMatchedRefLine(position: RefLinePosition): boolean;
/**
* alias getVRefLines
* @returns
*/
matchVRefLines(): MatchedLine<T>[];
getVRefLines(): MatchedLine<T>[];
/**
* alias getHRefLines
* @returns
*/
matchHRefLines(): MatchedLine<T>[];
getHRefLines(): MatchedLine<T>[];
/**
* alias getAllRefLines
* @returns
*/
matchAllRefLines(): MatchedLine<T>[];
getAllRefLines(): MatchedLine<T>[];
/**
* 适配偏移量,达到吸附效果
* @param type
* @param offset
* @param delta
* @param adsorbDistance
* @returns
*/
getOffsetAdsorbDelta(type: LineType, offset: number, delta: number, adsorbDistance?: number): number;
/**
* 适配偏移量,达到吸附效果
* @param delta
* @param adsorbDistance
* @returns
*/
getAdsorbDelta(delta: Delta, adsorbDistance?: number): Delta;
}

interface Rect {
key: string | number;
left: number;
top: number;
width: number;
height: number;
rotate?: number;
[x: string]: any;
}
interface BoundingRect {
left: number;
top: number;
right: number;
bottom: number;
width: number;
height: number;
}
declare type LineType = "horizontal" | "vertical";
declare type VRefLinePosition = "vl" | "vc" | "vr";
declare type HRefLinePosition = "ht" | "hc" | "hb";
declare type RefLinePosition = VRefLinePosition | HRefLinePosition;
interface RefLineMeta<T extends Rect = Rect> {
type: LineType;
position: RefLinePosition;
offset: number;
start: number;
end: number;
rect: T;
}
interface MatchedLine<T extends Rect = Rect> {
type: LineType;
left: number;
top: number;
size: number;
refLineMetaList: RefLineMeta<T>[];
}
interface LineGroup<T extends Rect = Rect> {
min: number;
max: number;
offset: number;
refLineMetaList: RefLineMeta<T>[];
}
interface Delta {
left: number;
top: number;
}
declare enum MOVE_DIR {
MOVE_TOP = 0,
MOVE_RIGHT = 1,
MOVE_BOTTOM = 2,
MOVE_LEFT = 3,
NONE = 4
}


```
34 changes: 34 additions & 0 deletions babel.config.base.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
const pkg = require("./package.json");
module.exports = function () {
return {
plugins: [
"babel-plugin-lodash",
[
"babel-plugin-transform-define",
{
__VERSION__: pkg.version,
},
],
[
"babel-plugin-module-resolver",
{
// root: ["./src"], // 仅限./src目录
alias: {
"~": "./src",
},
},
],
[
"babel-plugin-search-and-replace",
{
rules: [
{
search: "%VERSION%",
replace: pkg.version,
},
],
},
],
],
};
};
20 changes: 20 additions & 0 deletions babel.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
const getBaseConfig = require("./babel.config.base");

module.exports = api => {
const isTest = api.env("test");
if (!isTest) return {};

const babel = getBaseConfig();

return {
presets: [
[
"babel-preset-packez",
{
modules: "cjs",
},
],
],
plugins: babel.plugins,
};
};
Loading

0 comments on commit d99c523

Please sign in to comment.