-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest-resize.html
More file actions
177 lines (154 loc) · 4.67 KB
/
Copy pathtest-resize.html
File metadata and controls
177 lines (154 loc) · 4.67 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>AutoSizes Resize Test</title>
<style>
body {
font-family: system-ui;
padding: 20px;
}
.container {
background: #f0f0f0;
padding: 20px;
margin-bottom: 20px;
transition: width 0.3s;
}
.resizable {
width: 600px;
border: 2px solid #333;
}
img {
max-width: 100%;
height: auto;
border: 2px solid #4caf50;
}
.controls {
position: fixed;
top: 20px;
right: 20px;
background: white;
padding: 15px;
border: 2px solid #333;
border-radius: 8px;
}
button {
display: block;
width: 100%;
padding: 10px;
margin-bottom: 10px;
background: #1976d2;
color: white;
border: none;
border-radius: 4px;
cursor: pointer;
}
button:hover {
background: #1565c0;
}
.info {
background: #e3f2fd;
padding: 10px;
margin-top: 10px;
border-radius: 4px;
font-family: monospace;
font-size: 14px;
}
.log {
position: fixed;
bottom: 20px;
right: 20px;
width: 300px;
max-height: 200px;
overflow-y: auto;
background: #263238;
color: #aed581;
padding: 10px;
border-radius: 4px;
font-family: monospace;
font-size: 12px;
}
</style>
</head>
<body>
<h1>AutoSizes Resize Test</h1>
<div class="controls">
<button onclick="setWidth(300)">300px</button>
<button onclick="setWidth(600)">600px</button>
<button onclick="setWidth(900)">900px</button>
<button onclick="window.dispatchEvent(new Event('resize'))">Trigger Resize</button>
<button onclick="updateInfo()">Update Info</button>
</div>
<div class="container resizable" id="resizable">
<h2>Resizable Container</h2>
<p>Container width: <span id="containerWidth">600</span>px</p>
<img
class="autosizes"
sizes="auto"
srcset="https://via.placeholder.com/300x200?text=300w 300w,
https://via.placeholder.com/600x400?text=600w 600w,
https://via.placeholder.com/900x600?text=900w 900w,
https://via.placeholder.com/1200x800?text=1200w 1200w"
src="https://via.placeholder.com/600x400?text=fallback"
alt="Test image"
id="testImg"
/>
<div class="info">
<div><strong>sizes attribute:</strong> <span id="sizesValue">-</span></div>
<div><strong>img.offsetWidth:</strong> <span id="imgWidth">-</span>px</div>
<div><strong>Has autosized class:</strong> <span id="hasClass">-</span></div>
<div><strong>_autosizesWidth:</strong> <span id="internalWidth">-</span></div>
</div>
</div>
<div class="log" id="log"></div>
<script type="module">
import autoSizes from './index.js';
// Make available globally
window.autoSizes = autoSizes;
const log = (msg) => {
const logEl = document.getElementById('log');
const time = new Date().toLocaleTimeString();
logEl.innerHTML = `[${time}] ${msg}<br>` + logEl.innerHTML;
console.log(`[${time}] ${msg}`);
};
// Log resize events
let resizeCount = 0;
window.addEventListener('resize', () => {
resizeCount++;
log(`Resize event #${resizeCount}`);
});
// Log custom events
document.addEventListener('beforeSizesUpdate', (e) => {
log(`beforeSizesUpdate: width=${e.detail.width}`);
});
document.addEventListener('afterSizesUpdate', (e) => {
log(`afterSizesUpdate: sizes="${e.detail.sizes}"`);
updateInfo();
});
window.setWidth = (width) => {
const container = document.getElementById('resizable');
container.style.width = width + 'px';
document.getElementById('containerWidth').textContent = width;
log(`Container width set to ${width}px`);
// Wait for DOM update, then trigger resize
setTimeout(() => {
log('Dispatching resize event...');
window.dispatchEvent(new Event('resize'));
}, 50);
};
window.updateInfo = () => {
const img = document.getElementById('testImg');
document.getElementById('sizesValue').textContent = img.getAttribute('sizes') || 'auto';
document.getElementById('imgWidth').textContent = img.offsetWidth;
document.getElementById('hasClass').textContent = img.classList.contains('autosized') ? 'Yes' : 'No';
document.getElementById('internalWidth').textContent = img._autosizesWidth || 'not set';
};
// Initial info update
setTimeout(() => {
log('Page loaded, library initialized');
updateInfo();
}, 200);
</script>
</body>
</html>