def get_width(self): js = """ let canvas = document.createElement('canvas'); canvas.style.position = "absolute"; let ctx = canvas.getContext('2d'); document.body.appendChild(canvas); ctx.font = `16px Menlo, consolas, DejaVu Sans Mono, Courier New, monospace`; document.body.removeChild(canvas); let text = ctx.measureText('0'); ctx.fillText('0', 50, 50); ($('#pywebio-scope-{scope}').width()-16)/\ $('#pywebio-scope-{scope}').css('font-size').slice(0, -2)/text.width*16;\ """.format(scope=self.scope) width = eval_js(js) return 80 if width is None else 128 if width > 128 else int(width)
def get_localstorage(key): return eval_js("localStorage.getItem(key)", key=key)
def get_window_visibility_state(): ret = eval_js("document.visibilityState") return False if ret == "hidden" else True