Skip to content

Commit b192aef

Browse files
adumesnycursoragent
andcommitted
fix landscape printing width using vmax
Co-authored-by: Cursor <cursoragent@cursor.com>
1 parent 1f2bf75 commit b192aef

1 file changed

Lines changed: 35 additions & 3 deletions

File tree

src/gridstack.scss

Lines changed: 35 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -151,19 +151,51 @@
151151
}
152152

153153
@media print {
154+
@page gs-landscape {
155+
size: landscape;
156+
}
157+
@page gs-portrait {
158+
size: portrait;
159+
}
160+
161+
/* Use native CSS Grid instead of floats for printing to perfectly respect
162+
visual coordinates and dimensions while maintaining layout flow */
154163
.grid-stack {
164+
display: grid !important;
165+
grid-template-columns: repeat(var(--gs-columns, 12), minmax(0, 1fr)) !important;
166+
grid-auto-rows: var(--gs-cell-height) !important;
155167
height: auto !important;
156168
}
157169
.grid-stack > .grid-stack-item {
158170
position: relative !important;
171+
float: none !important;
172+
width: auto !important;
173+
height: auto !important;
159174
left: auto !important;
160175
top: auto !important;
161-
float: left;
176+
177+
/* Apply GS coordinates natively via the injected CSS vars */
178+
grid-column-start: calc(var(--gs-x) + 1) !important;
179+
grid-column-end: span var(--gs-w) !important;
180+
grid-row-start: calc(var(--gs-y) + 1) !important;
181+
grid-row-end: span var(--gs-h) !important;
162182
}
163183
.grid-stack > .grid-stack-item[gs-page-break="true"] {
164184
page-break-before: always !important;
165185
break-before: page !important;
166-
float: none !important;
167-
clear: both !important;
186+
}
187+
.grid-stack > .grid-stack-item[gs-print-hide="true"] {
188+
display: none !important;
189+
}
190+
.grid-stack > .grid-stack-item[gs-print-orientation="landscape"] {
191+
page: gs-landscape;
192+
/* Force item to take proper landscape width, overriding portrait grid track sizing.
193+
vmax ensures we get the long edge of the paper regardless of default printer orientation */
194+
min-width: calc(100vmax * var(--gs-w) / var(--gs-columns, 12)) !important;
195+
}
196+
.grid-stack > .grid-stack-item[gs-print-orientation="portrait"] {
197+
page: gs-portrait;
198+
/* vmin ensures we get the short edge of the paper */
199+
min-width: calc(100vmin * var(--gs-w) / var(--gs-columns, 12)) !important;
168200
}
169201
}

0 commit comments

Comments
 (0)