declare let __webpack_public_path__ ; __webpack_public_path__ = ( window as any ) . __jupyter_widgets_assets_path__ || __webpack_public_path__ ; import '@fortawesome/fontawesome-free/css/all.min.css' ; import '@fortawesome/fontawesome-free/css/v4-shims.min.css' ; import '@lumino/widgets/style/index.css' ; import '@jupyter-widgets/controls/css/widgets-base.css' ; if ( getComputedStyle ( document . documentElement ) . getPropertyValue ( '--jp-layout-color0' ) === '' ) { require ( '@jupyter-widgets/controls/css/labvariables.css' ) ; } import { HTMLManager } from './index' ; import Ajv from 'ajv' ; import { IManagerState } from '@jupyter-widgets/base-manager' ; const widget_state_schema = require ( '@jupyter-widgets/schema' ) . v2 . state ; const widget_view_schema = require ( '@jupyter-widgets/schema' ) . v2 . view ; interface IViewState { version_major : number ; version_minor : number ; model_id : string ; } const ajv = new Ajv ( ) ; const model_validate = ajv . compile < IManagerState > ( widget_state_schema ) ; const view_validate = ajv . compile < IViewState > ( widget_view_schema ) ; param managerFactory param element export async function renderWidgets ( managerFactory , element = document . documentElement ) { const tags = element . querySelectorAll ( 'script[type="application/vnd.jupyter.widget-state+json"]' ) ; await Promise . all ( Array . from ( tags ) . map ( async ( t ) => renderManager ( element , JSON . parse ( t . innerHTML ) , managerFactory ) ) ) ; } param element param widgetState async function renderManager ( element , widgetState , managerFactory ) { const valid = model_validate ( widgetState ) ; if ( ! valid ) { throw new Error ( `Model state has errors: ${ model_validate . errors }` ) ; } const manager = managerFactory ( ) ; const models = await manager . set_state ( widgetState as IManagerState ) ; const tags = element . querySelectorAll ( 'script[type="application/vnd.jupyter.widget-view+json"]' ) ; await Promise . all ( Array . from ( tags ) . map ( async ( viewtag ) => { const widgetViewObject = JSON . parse ( viewtag . innerHTML ) ; const valid = view_validate ( widgetViewObject ) ; if ( ! valid ) { throw new Error ( `View state has errors: ${ view_validate . errors }` ) ; } const model_id = widgetViewObject . model_id ; const model = models . find ( ( item ) => item . model_id == model_id ) ; if ( model !== undefined && viewtag . parentElement !== null ) { const prev = viewtag . previousElementSibling ; if ( prev && prev . tagName === 'img' && prev . classList . contains ( 'jupyter-widget' ) ) { viewtag . parentElement . removeChild ( prev ) ; } const widgetTag = document . createElement ( 'div' ) ; widgetTag . className = 'widget-subarea' ; viewtag . parentElement . insertBefore ( widgetTag , viewtag ) ; const view = await manager . create_view ( model ) ; manager . display_view ( view , widgetTag ) ; } } ) ) ; }