zcw-shared 1.23.0 → 1.24.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/functions/dom/computePosition.d.ts +6 -0
- package/dist/functions/dom/computePosition.js +49 -0
- package/dist/functions/dom/computePosition.js.map +1 -0
- package/dist/functions/dom/getAlignment.d.ts +2 -0
- package/dist/functions/dom/getAlignment.js +5 -0
- package/dist/functions/dom/getAlignment.js.map +1 -0
- package/dist/functions/dom/getBasePlacement.d.ts +2 -0
- package/dist/functions/dom/getBasePlacement.js +4 -0
- package/dist/functions/dom/getBasePlacement.js.map +1 -0
- package/dist/functions/dom/getCrossAxisFlip.d.ts +2 -0
- package/dist/functions/dom/getCrossAxisFlip.js +11 -0
- package/dist/functions/dom/getCrossAxisFlip.js.map +1 -0
- package/dist/functions/dom/getFlipPlacements.d.ts +2 -0
- package/dist/functions/dom/getFlipPlacements.js +13 -0
- package/dist/functions/dom/getFlipPlacements.js.map +1 -0
- package/dist/functions/dom/getMainAxisFlip.d.ts +2 -0
- package/dist/functions/dom/getMainAxisFlip.js +17 -0
- package/dist/functions/dom/getMainAxisFlip.js.map +1 -0
- package/dist/functions/dom/isValidPlacement.d.ts +2 -0
- package/dist/functions/dom/isValidPlacement.js +16 -0
- package/dist/functions/dom/isValidPlacement.js.map +1 -0
- package/package.json +9 -1
- package/types/placement.d.ts +15 -0
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import type { Placement } from '../../../types/placement';
|
|
2
|
+
import type { Rect, Coords } from '../../../types/geometry';
|
|
3
|
+
export declare function computePosition(placement: Placement, reference: Rect, floating: {
|
|
4
|
+
width: number;
|
|
5
|
+
height: number;
|
|
6
|
+
}, scrollOffset: Coords): Coords;
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
import { getBasePlacement } from './getBasePlacement';
|
|
2
|
+
import { getAlignment } from './getAlignment';
|
|
3
|
+
export function computePosition(placement, reference, floating, scrollOffset) {
|
|
4
|
+
const basePlacement = getBasePlacement(placement);
|
|
5
|
+
const alignment = getAlignment(placement);
|
|
6
|
+
let x = reference.x;
|
|
7
|
+
let y = reference.y;
|
|
8
|
+
switch (basePlacement) {
|
|
9
|
+
case 'top':
|
|
10
|
+
x = x + reference.width / 2 - floating.width / 2;
|
|
11
|
+
y = reference.y - floating.height;
|
|
12
|
+
break;
|
|
13
|
+
case 'bottom':
|
|
14
|
+
x = x + reference.width / 2 - floating.width / 2;
|
|
15
|
+
y = reference.y + reference.height;
|
|
16
|
+
break;
|
|
17
|
+
case 'left':
|
|
18
|
+
x = x - floating.width;
|
|
19
|
+
y = y + reference.height / 2 - floating.height / 2;
|
|
20
|
+
break;
|
|
21
|
+
case 'right':
|
|
22
|
+
x = x + reference.width;
|
|
23
|
+
y = y + reference.height / 2 - floating.height / 2;
|
|
24
|
+
break;
|
|
25
|
+
}
|
|
26
|
+
if (alignment) {
|
|
27
|
+
if (basePlacement === 'top' || basePlacement === 'bottom') {
|
|
28
|
+
if (alignment === 'start') {
|
|
29
|
+
x = reference.x;
|
|
30
|
+
}
|
|
31
|
+
else if (alignment === 'end') {
|
|
32
|
+
x = reference.x + reference.width - floating.width;
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
else {
|
|
36
|
+
if (alignment === 'start') {
|
|
37
|
+
y = reference.y;
|
|
38
|
+
}
|
|
39
|
+
else if (alignment === 'end') {
|
|
40
|
+
y = reference.y + reference.height - floating.height;
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
return {
|
|
45
|
+
x: x + scrollOffset.x,
|
|
46
|
+
y: y + scrollOffset.y,
|
|
47
|
+
};
|
|
48
|
+
}
|
|
49
|
+
//# sourceMappingURL=computePosition.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"computePosition.js","sourceRoot":"","sources":["../../../src/functions/dom/computePosition.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,gBAAgB,EAAE,MAAM,oB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Aa,KAAK,QAAQ,EAAE,CAAC;YAE1D,IAAI,SAAS,KAAK,OAAO,EAAE,CAAC;gBAC1B,CAAC,GAAG,SAAS,CAAC,CAAC,CAAA;YACjB,CAAC;iBAAM,IAAI,SAAS,KAAK,KAAK,EAAE,CAAC;gBAC/B,CAAC,GAAG,SAAS,CAAC,CAAC,GAAG,SAAS,CAAC,KAAK,GAAG,QAAQ,CAAC,KAAK,CAAA;YACpD,CAAC;QACH,CAAC;aAAM,CAAC;YAEN,IAAI,SAAS,KAAK,OAAO,EAAE,CAAC;gBAC1B,CAAC,GAAG,SAAS,CAAC,CAAC,CAAA;YACjB,CAAC;iBAAM,IAAI,SAAS,KAAK,KAAK,EAAE,CAAC;gBAC/B,CAAC,GAAG,SAAS,CAAC,CAAC,GAAG,SAAS,CAAC,MAAM,GAAG,QAAQ,CAAC,MAAM,CAAA;YACtD,CAAC;QACH,CAAC;IACH,CAAC;IAGD,OAAO;QACL,CAAC,EAAE,CAAC,GAAG,YAAY,CAAC,CAAC;QACrB,CAAC,EAAE,CAAC,GAAG,YAAY,CAAC,CAAC;KACtB,CAAA;AACH,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"getAlignment.js","sourceRoot":"","sources":["../../../src/functions/dom/getAlignment.ts"],"names":[],"mappings":"AAkBA,MAAM,UAAU,YAAY,CAAC,SAAoB;IAC/C,MAAM,KAAK,GAAG,SAAS,CAAC,KAAK,CAAC,GAAG,CAAC,CAAA;IAClC,OAAO,KAAK,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC,CAAE,KAAK,CAAC,CAAC,CAAe,CAAC,CAAC,CAAC,IAAI,CAAA;AAC1D,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"getBasePlacement.js","sourceRoot":"","sources":["../../../src/functions/dom/getBasePlacement.ts"],"names":[],"mappings":"AAkBA,MAAM,UAAU,gBAAgB,CAAC,SAAoB;IACnD,OAAO,SAAS,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,CAAC,CAAkB,CAAA;AACjD,CAAC"}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { getBasePlacement } from './getBasePlacement';
|
|
2
|
+
import { getAlignment } from './getAlignment';
|
|
3
|
+
export function getCrossAxisFlip(placement) {
|
|
4
|
+
const basePlacement = getBasePlacement(placement);
|
|
5
|
+
const alignment = getAlignment(placement);
|
|
6
|
+
if (!alignment)
|
|
7
|
+
return placement;
|
|
8
|
+
const newAlignment = alignment === 'start' ? 'end' : 'start';
|
|
9
|
+
return `${basePlacement}-${newAlignment}`;
|
|
10
|
+
}
|
|
11
|
+
//# sourceMappingURL=getCrossAxisFlip.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"getCrossAxisFlip.js","sourceRoot":"","sources":["../../../src/functions/dom/getCrossAxisFlip.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,gBAAgB,EAAE,MAAM,oBAAoB,CAAA;AACrD,OAAO,EAAE,YAAY,EAAE,MAAM,gBAAgB,CAAA;AAmB7C,MAAM,UAAU,gBAAgB,CAAC,SAAoB;IACnD,MAAM,aAAa,GAAG,gBAAgB,CAAC,SAAS,CAAC,CAAA;IACjD,MAAM,SAAS,GAAG,YAAY,CAAC,SAAS,CAAC,CAAA;IAEzC,IAAI,CAAC,SAAS;QAAE,OAAO,SAAS,CAAA;IAEhC,MAAM,YAAY,GAAc,SAAS,KAAK,OAAO,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,OAAO,CAAA;IACvE,OAAO,GAAG,aAAa,IAAI,YAAY,EAAe,CAAA;AACxD,CAAC"}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { getBasePlacement } from './getBasePlacement';
|
|
2
|
+
import { getAlignment } from './getAlignment';
|
|
3
|
+
export function getFlipPlacements(placement) {
|
|
4
|
+
const basePlacement = getBasePlacement(placement);
|
|
5
|
+
const alignment = getAlignment(placement);
|
|
6
|
+
const allBasePlacements = ['top', 'right', 'bottom', 'left'];
|
|
7
|
+
const otherBasePlacements = allBasePlacements.filter(p => p !== basePlacement);
|
|
8
|
+
if (!alignment) {
|
|
9
|
+
return otherBasePlacements;
|
|
10
|
+
}
|
|
11
|
+
return otherBasePlacements.map(base => `${base}-${alignment}`);
|
|
12
|
+
}
|
|
13
|
+
//# sourceMappingURL=getFlipPlacements.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"getFlipPlacements.js","sourceRoot":"","sources":["../../../src/functions/dom/getFlipPlacements.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,gBAAgB,EAAE,MAAM,oBAAoB,CAAA;AACrD,OAAO,EAAE,YAAY,EAAE,MAAM,gBAAgB,CAAA;AAiB7C,MAAM,UAAU,iBAAiB,CAAC,SAAoB;IACpD,MAAM,aAAa,GAAG,gBAAgB,CAAC,SAAS,CAAC,CAAA;IACjD,MAAM,SAAS,GAAG,YAAY,CAAC,SAAS,CAAC,CAAA;IAEzC,MAAM,iBAAiB,GAAoB,CAAC,KAAK,EAAE,OAAO,EAAE,QAAQ,EAAE,MAAM,CAAC,CAAA;IAC7E,MAAM,mBAAmB,GAAG,iBAAiB,CAAC,MAAM,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,KAAK,aAAa,CAAC,CAAA;IAE9E,IAAI,CAAC,SAAS,EAAE,CAAC;QAEf,OAAO,mBAAkC,CAAA;IAC3C,CAAC;IAGD,OAAO,mBAAmB,CAAC,GAAG,CAC5B,IAAI,CAAC,EAAE,CAAC,GAAG,IAAI,IAAI,SAAS,EAAe,CAC5C,CAAA;AACH,CAAC"}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { getBasePlacement } from './getBasePlacement';
|
|
2
|
+
import { getAlignment } from './getAlignment';
|
|
3
|
+
export function getMainAxisFlip(placement) {
|
|
4
|
+
const basePlacement = getBasePlacement(placement);
|
|
5
|
+
const alignment = getAlignment(placement);
|
|
6
|
+
const flips = {
|
|
7
|
+
top: 'bottom',
|
|
8
|
+
bottom: 'top',
|
|
9
|
+
left: 'right',
|
|
10
|
+
right: 'left',
|
|
11
|
+
};
|
|
12
|
+
const flippedBase = flips[basePlacement];
|
|
13
|
+
return alignment
|
|
14
|
+
? `${flippedBase}-${alignment}`
|
|
15
|
+
: flippedBase;
|
|
16
|
+
}
|
|
17
|
+
//# sourceMappingURL=getMainAxisFlip.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"getMainAxisFlip.js","sourceRoot":"","sources":["../../../src/functions/dom/getMainAxisFlip.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,gBAAgB,EAAE,MAAM,oBAAoB,CAAA;AACrD,OAAO,EAAE,YAAY,EAAE,MAAM,gBAAgB,CAAA;AAkB7C,MAAM,UAAU,eAAe,CAAC,SAAoB;IAClD,MAAM,aAAa,GAAG,gBAAgB,CAAC,SAAS,CAAC,CAAA;IACjD,MAAM,SAAS,GAAG,YAAY,CAAC,SAAS,CAAC,CAAA;IAEzC,MAAM,KAAK,GAAyC;QAClD,GAAG,EAAE,QAAQ;QACb,MAAM,EAAE,KAAK;QACb,IAAI,EAAE,OAAO;QACb,KAAK,EAAE,MAAM;KACd,CAAA;IAED,MAAM,WAAW,GAAG,KAAK,CAAC,aAAa,CAAC,CAAA;IACxC,OAAO,SAAS;QACd,CAAC,CAAE,GAAG,WAAW,IAAI,SAAS,EAAgB;QAC9C,CAAC,CAAE,WAAyB,CAAA;AAChC,CAAC"}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
export function isValidPlacement(placement) {
|
|
2
|
+
const validBasePlacements = ['top', 'right', 'bottom', 'left'];
|
|
3
|
+
const validAlignments = ['start', 'end'];
|
|
4
|
+
const parts = placement.split('-');
|
|
5
|
+
if (parts.length > 2 || parts.length === 0) {
|
|
6
|
+
return false;
|
|
7
|
+
}
|
|
8
|
+
if (!validBasePlacements.includes(parts[0])) {
|
|
9
|
+
return false;
|
|
10
|
+
}
|
|
11
|
+
if (parts.length === 2 && !validAlignments.includes(parts[1])) {
|
|
12
|
+
return false;
|
|
13
|
+
}
|
|
14
|
+
return true;
|
|
15
|
+
}
|
|
16
|
+
//# sourceMappingURL=isValidPlacement.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"isValidPlacement.js","sourceRoot":"","sources":["../../../src/functions/dom/isValidPlacement.ts"],"names":[],"mappings":"AAmBA,MAAM,UAAU,gBAAgB,CAAC,SAAiB;IAChD,MAAM,mBAAmB,GAAoB,CAAC,KAAK,EAAE,OAAO,EAAE,QAAQ,EAAE,MAAM,CAAC,CAAA;IAC/E,MAAM,eAAe,GAAgB,CAAC,OAAO,EAAE,KAAK,CAAC,CAAA;IAGrD,MAAM,KAAK,GAAG,SAAS,CAAC,KAAK,CAAC,GAAG,CAAC,CAAA;IAClC,IAAI,KAAK,CAAC,MAAM,GAAG,CAAC,IAAI,KAAK,CAAC,MAAM,KAAK,CAAC,EAAE,CAAC;QAC3C,OAAO,KAAK,CAAA;IACd,CAAC;IAGD,IAAI,CAAC,mBAAmB,CAAC,QAAQ,CAAC,KAAK,CAAC,CAAC,CAAkB,CAAC,EAAE,CAAC;QAC7D,OAAO,KAAK,CAAA;IACd,CAAC;IAGD,IAAI,KAAK,CAAC,MAAM,KAAK,CAAC,IAAI,CAAC,eAAe,CAAC,QAAQ,CAAC,KAAK,CAAC,CAAC,CAAc,CAAC,EAAE,CAAC;QAC3E,OAAO,KAAK,CAAA;IACd,CAAC;IAED,OAAO,IAAI,CAAA;AACb,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "zcw-shared",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.24.0",
|
|
4
4
|
"files": [
|
|
5
5
|
"references",
|
|
6
6
|
"dist",
|
|
@@ -119,12 +119,19 @@
|
|
|
119
119
|
"./functions/design-tokens/generateVariables": "./dist/functions/design-tokens/generateVariables.js",
|
|
120
120
|
"./functions/design-tokens/mixColors": "./dist/functions/design-tokens/mixColors.js",
|
|
121
121
|
"./functions/design-tokens/parseDesignTokens": "./dist/functions/design-tokens/parseDesignTokens.js",
|
|
122
|
+
"./functions/dom/computePosition": "./dist/functions/dom/computePosition.js",
|
|
122
123
|
"./functions/dom/createThrottledEventListener": "./dist/functions/dom/createThrottledEventListener.js",
|
|
123
124
|
"./functions/dom/demonstrateResourceLoading": "./dist/functions/dom/demonstrateResourceLoading.js",
|
|
124
125
|
"./functions/dom/detectOverflow": "./dist/functions/dom/detectOverflow.js",
|
|
126
|
+
"./functions/dom/getAlignment": "./dist/functions/dom/getAlignment.js",
|
|
127
|
+
"./functions/dom/getBasePlacement": "./dist/functions/dom/getBasePlacement.js",
|
|
128
|
+
"./functions/dom/getCrossAxisFlip": "./dist/functions/dom/getCrossAxisFlip.js",
|
|
125
129
|
"./functions/dom/getElementRect": "./dist/functions/dom/getElementRect.js",
|
|
130
|
+
"./functions/dom/getFlipPlacements": "./dist/functions/dom/getFlipPlacements.js",
|
|
131
|
+
"./functions/dom/getMainAxisFlip": "./dist/functions/dom/getMainAxisFlip.js",
|
|
126
132
|
"./functions/dom/getRelativePosition": "./dist/functions/dom/getRelativePosition.js",
|
|
127
133
|
"./functions/dom/getViewportRect": "./dist/functions/dom/getViewportRect.js",
|
|
134
|
+
"./functions/dom/isValidPlacement": "./dist/functions/dom/isValidPlacement.js",
|
|
128
135
|
"./functions/file/formatFileSize": "./dist/functions/file/formatFileSize.js",
|
|
129
136
|
"./functions/file/getFileExtension": "./dist/functions/file/getFileExtension.js",
|
|
130
137
|
"./functions/functional/compose": "./dist/functions/functional/compose.js",
|
|
@@ -285,6 +292,7 @@
|
|
|
285
292
|
"./types/color": "./types/color.d.ts",
|
|
286
293
|
"./types/design-system": "./types/design-system.d.ts",
|
|
287
294
|
"./types/geometry": "./types/geometry.d.ts",
|
|
295
|
+
"./types/placement": "./types/placement.d.ts",
|
|
288
296
|
"./types/platform": "./types/platform.d.ts",
|
|
289
297
|
"./types/reactive": "./types/reactive.d.ts",
|
|
290
298
|
"./types/semver": "./types/semver.d.ts",
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 基础定位方向类型
|
|
3
|
+
*/
|
|
4
|
+
export type BasePlacement = 'top' | 'right' | 'bottom' | 'left'
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* 对齐方式类型
|
|
8
|
+
*/
|
|
9
|
+
export type Alignment = 'start' | 'end'
|
|
10
|
+
|
|
11
|
+
/**
|
|
12
|
+
* 弹出层位置类型
|
|
13
|
+
*/
|
|
14
|
+
export type Placement = BasePlacement | `${BasePlacement}-${Alignment}`
|
|
15
|
+
|