masua 0.11.3 → 0.11.5
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/README.md +1 -1
- package/index.ts +10 -8
- package/package.json +13 -22
package/README.md
CHANGED
|
@@ -43,7 +43,7 @@ grid(document.querySelector('#my-custom-grid'), {
|
|
|
43
43
|
import { Grid } from 'masua/react'
|
|
44
44
|
|
|
45
45
|
const MyGrid = () => (
|
|
46
|
-
<Grid disabled={window.innerWidth < 501}>
|
|
46
|
+
<Grid disabled={window.innerWidth < 501} gutter={50}>
|
|
47
47
|
<Box />
|
|
48
48
|
<Box size={3} />
|
|
49
49
|
<Box size={2} />
|
package/index.ts
CHANGED
|
@@ -21,7 +21,7 @@ interface State {
|
|
|
21
21
|
}
|
|
22
22
|
|
|
23
23
|
export interface Configuration {
|
|
24
|
-
baseWidth: number
|
|
24
|
+
baseWidth: number | string
|
|
25
25
|
gutter: number | string
|
|
26
26
|
gutterX: number | string
|
|
27
27
|
gutterY: number | string
|
|
@@ -33,6 +33,7 @@ export interface Configuration {
|
|
|
33
33
|
}
|
|
34
34
|
|
|
35
35
|
interface NumberConfiguration extends Configuration {
|
|
36
|
+
baseWidth: number
|
|
36
37
|
gutter: number
|
|
37
38
|
gutterX: number
|
|
38
39
|
gutterY: number
|
|
@@ -52,7 +53,7 @@ function getCount(state: State) {
|
|
|
52
53
|
function getLongest(state: State) {
|
|
53
54
|
let longest = 0
|
|
54
55
|
for (let index = 0; index < state.count; index += 1) {
|
|
55
|
-
if (state.columns[index] > state.columns[longest]) {
|
|
56
|
+
if ((state.columns[index] ?? 0) > (state.columns[longest] ?? 1)) {
|
|
56
57
|
longest = index
|
|
57
58
|
}
|
|
58
59
|
}
|
|
@@ -66,7 +67,7 @@ function getNextColumn(index: number, state: State) {
|
|
|
66
67
|
function getShortest(state: State) {
|
|
67
68
|
let shortest = 0
|
|
68
69
|
for (let index = 0; index < state.count; index += 1) {
|
|
69
|
-
if (state.columns[index] < state.columns[shortest]) {
|
|
70
|
+
if ((state.columns[index] ?? 1) < (state.columns[shortest] ?? 0)) {
|
|
70
71
|
shortest = index
|
|
71
72
|
}
|
|
72
73
|
}
|
|
@@ -174,15 +175,15 @@ function layout(state: State) {
|
|
|
174
175
|
} else {
|
|
175
176
|
x = startX - (colWidth + childrenGutter) * nextColumn - colWidth
|
|
176
177
|
}
|
|
177
|
-
const y = state.columns[nextColumn]
|
|
178
|
+
const y = state.columns[nextColumn] ?? 0
|
|
178
179
|
const child = children[index] as HTMLElement
|
|
179
180
|
child.style.transform = `translate3d(${Math.round(x)}px,${Math.round(y)}px,0)`
|
|
180
181
|
child.style.position = 'absolute'
|
|
181
182
|
|
|
182
|
-
state.columns[nextColumn] += state.sizes[index] + (state.count > 1 ? state.gutterY : state.singleColumnGutter) // margin-bottom
|
|
183
|
+
state.columns[nextColumn] += (state.sizes[index] ?? 0) + (state.count > 1 ? state.gutterY : state.singleColumnGutter) // margin-bottom
|
|
183
184
|
}
|
|
184
185
|
|
|
185
|
-
state.container.style.height = `${state.columns[getLongest(state)] - state.currentGutterY}px`
|
|
186
|
+
state.container.style.height = `${(state.columns[getLongest(state)] ?? 0) - state.currentGutterY}px`
|
|
186
187
|
}
|
|
187
188
|
|
|
188
189
|
function resizeThrottler(state: State) {
|
|
@@ -257,13 +258,14 @@ function getSizeInPixels(size: string) {
|
|
|
257
258
|
return pixels
|
|
258
259
|
}
|
|
259
260
|
|
|
260
|
-
const sizeValues: (keyof Configuration)[] = ['gutter', 'gutterX', 'gutterY', 'singleColumnGutter']
|
|
261
|
+
const sizeValues: (keyof Configuration)[] = ['baseWidth', 'gutter', 'gutterX', 'gutterY', 'singleColumnGutter']
|
|
261
262
|
|
|
262
263
|
function convertStringSizesToPixels(configuration: Partial<Configuration>): Partial<NumberConfiguration> {
|
|
263
264
|
for (const property of sizeValues) {
|
|
264
265
|
const value = configuration[property]
|
|
265
266
|
if (typeof value === 'string') {
|
|
266
|
-
|
|
267
|
+
// @ts-ignore No idea what's the issue here.
|
|
268
|
+
configuration[property] = getSizeInPixels(value)
|
|
267
269
|
}
|
|
268
270
|
}
|
|
269
271
|
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "masua",
|
|
3
3
|
"description": "Simple masonry layout library in TypeScript.",
|
|
4
|
-
"version": "0.11.
|
|
4
|
+
"version": "0.11.5",
|
|
5
5
|
"repository": "github:tobua/masua",
|
|
6
6
|
"homepage": "https://tobua.github.io/masua",
|
|
7
7
|
"license": "MIT",
|
|
@@ -12,14 +12,14 @@
|
|
|
12
12
|
"scripts": {
|
|
13
13
|
"format": "bun biome format . --write",
|
|
14
14
|
"lint": "bun biome lint .",
|
|
15
|
-
"types": "tsc
|
|
15
|
+
"types": "tsc"
|
|
16
16
|
},
|
|
17
17
|
"devDependencies": {
|
|
18
18
|
"@biomejs/biome": "^1.7.1",
|
|
19
|
-
"@types/bun": "^1.1.
|
|
20
|
-
"@types/react": "^18.
|
|
19
|
+
"@types/bun": "^1.1.1",
|
|
20
|
+
"@types/react": "^18.3.1",
|
|
21
21
|
"typescript": "^5.4.5",
|
|
22
|
-
"zero-configuration": "^0.
|
|
22
|
+
"zero-configuration": "^0.6.0"
|
|
23
23
|
},
|
|
24
24
|
"peerDependencies": {
|
|
25
25
|
"react": ">= 18",
|
|
@@ -33,6 +33,9 @@
|
|
|
33
33
|
"trustedDependencies": [
|
|
34
34
|
"zero-configuration"
|
|
35
35
|
],
|
|
36
|
+
"workspaces": [
|
|
37
|
+
"demo"
|
|
38
|
+
],
|
|
36
39
|
"type": "module",
|
|
37
40
|
"sideEffects": false,
|
|
38
41
|
"main": "./index.ts",
|
|
@@ -60,21 +63,12 @@
|
|
|
60
63
|
"publishConfig": {
|
|
61
64
|
"provenance": true
|
|
62
65
|
},
|
|
63
|
-
"engines": {
|
|
64
|
-
"node": ">= 18"
|
|
65
|
-
},
|
|
66
66
|
"configuration": {
|
|
67
|
-
"gitignore": "
|
|
68
|
-
"vscode": "
|
|
67
|
+
"gitignore": "bundle",
|
|
68
|
+
"vscode": "biome",
|
|
69
69
|
"typescript": {
|
|
70
|
+
"extends": "plugin",
|
|
70
71
|
"compilerOptions": {
|
|
71
|
-
"strict": true,
|
|
72
|
-
"skipLibCheck": true,
|
|
73
|
-
"lib": [
|
|
74
|
-
"DOM",
|
|
75
|
-
"ES2020"
|
|
76
|
-
],
|
|
77
|
-
"module": "Preserve",
|
|
78
72
|
"jsx": "react-jsx"
|
|
79
73
|
},
|
|
80
74
|
"files": [
|
|
@@ -89,12 +83,9 @@
|
|
|
89
83
|
"nursery": {
|
|
90
84
|
"all": true
|
|
91
85
|
}
|
|
92
|
-
}
|
|
93
|
-
"ignore": [
|
|
94
|
-
"demo"
|
|
95
|
-
]
|
|
86
|
+
}
|
|
96
87
|
},
|
|
97
|
-
"
|
|
88
|
+
"files": {
|
|
98
89
|
"ignore": [
|
|
99
90
|
"demo"
|
|
100
91
|
]
|