← Commit history

0.7.4: keep a positioned host container's positioning

Colby Knox ·554fef1847 · ·parent 7d3a8e9
5 files changed +19−5
README.md+1−1
@@ -143,7 +143,7 @@ toward the cursor, the cube faces with Home and Fit, hold Space to spin. The `?` key and Escape toggle the card. The first time a model is ready in a browser, a tip bubble says the Shift+Alt line once and is then remembered (ephemeral storage in sandboxed frames). `init(host, { showHelp: false })`-hides all of it for hosts that draw their own help; `viewer.showHelp()` and+hides all of it for hosts that draw their own help (0.7.4: a host container that is already positioned, such as `position: absolute; inset: 0`, keeps its positioning; 0.7.3 forced it to relative, and the canvas collapsed to 150 px after the host hid and re-showed the viewer); `viewer.showHelp()` and `viewer.hideHelp()` drive the card. `npm run test:help` covers it.  ### View cube: click on release, drag to orbit
VERSION+1−1
@@ -1 +1 @@-0.7.3+0.7.4
package.json+1−1
@@ -1,6 +1,6 @@ {   "name": "adom-3d-viewer-babylon9",-  "version": "0.7.3",+  "version": "0.7.4",   "description": "The Babylon 9.5 engine behind every component page's 3D tab on wiki.adom.inc. Versioned ESM bundle with GLB loading, view cube, layers toolbar, ground shadows, and Z-up CAD framing.",   "type": "app",   "main": "./dist/index.js",
standalone.ts+5−1
@@ -204,7 +204,11 @@ function mountHelp(container: HTMLElement) {   if (!doc.getElementById(HELP_STYLE_ID)) {     const st = doc.createElement('style'); st.id = HELP_STYLE_ID; st.textContent = HELP_CSS; doc.head.appendChild(st);   }-  if (!container.style.position) container.style.position = 'relative';+  // Only a STATIC container needs positioning for the absolute ? button. A host+  // that already positions it (the wiki's #viewer-wrap is absolute, inset 0)+  // must keep that: forcing relative collapsed the canvas to its 150 px default+  // after the host hid and re-showed the viewer.+  if (doc.defaultView && doc.defaultView.getComputedStyle(container).position === 'static') container.style.position = 'relative';    const btn = doc.createElement('button');   btn.type = 'button'; btn.className = 'a3d-help-btn'; btn.textContent = '?';
test/help.test.mjs+11−1
@@ -28,7 +28,7 @@ function makeBoxGlb() {   return Buffer.concat([header, ch(jsonBuf.length, "JSON"), jsonBuf, ch(bin.length, "BIN\0"), bin]); } const GLB = makeBoxGlb();-const HARNESS = (showHelp) => `<!doctype html><html><head><meta charset="utf-8"><style>html,body{margin:0;height:100%;background:#000}#wrap{position:relative;width:640px;height:400px}</style></head><body><div id="wrap"></div>+const HARNESS = (showHelp) => `<!doctype html><html><head><meta charset="utf-8"><style>html,body{margin:0;height:100%;background:#000}#host{position:relative;width:640px;height:400px}#wrap{position:absolute;inset:0}</style></head><body><div id="host"><div id="wrap"></div></div> <script type="module">   await import('/adom-3d-viewer-babylon9.esm.js');   const v = window.Adom3DViewerBabylon9.init(document.getElementById('wrap'), { zUp: true, showViewCube: false, showGround: false, modelUrl: '/chip.glb'${showHelp ? "" : ", showHelp: false"} });@@ -85,6 +85,16 @@ try {   await page.evaluate(() => window.__viewer.showHelp());   assert(await page.$eval(".a3d-help-card", c => !c.hidden), "showHelp() opens it"); +  section("the host's own positioning survives, and the canvas refills after a hide/show");+  assert(await page.$eval("#wrap", w => getComputedStyle(w).position) === "absolute", "an absolute host container stays absolute (was forced to relative)");+  assert(await page.$eval("#wrap", w => w.style.position) === "", "no inline position written onto a positioned host");+  await page.evaluate(() => { document.getElementById("host").style.display = "none"; window.dispatchEvent(new Event("resize")); });+  await sleep(300);+  await page.evaluate(() => { document.getElementById("host").style.display = ""; window.dispatchEvent(new Event("resize")); });+  await sleep(600);+  const h = await page.$eval("canvas", c => Math.round(c.getBoundingClientRect().height));+  assert(h >= 390, `the canvas is back to the host's height after hide/show (${h}px, not the 150px default)`);+   section("second load in the same browser: no tip again");   await page.goto(`http://127.0.0.1:${port}/help.html`, { waitUntil: "load", timeout: 90000 });   await page.waitForFunction(() => window.__ready === true, { timeout: 90000 });