@playcanvas/supersplat-viewer 1.39.0 → 1.40.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.d.ts +90 -1
- package/dist/index.js +3 -3
- package/dist/index.js.map +1 -1
- package/dist/viewer.css +34 -7
- package/dist/viewer.d.ts +15 -7
- package/dist/viewer.js +715 -210
- package/dist/viewer.js.map +1 -1
- package/package.json +1 -1
- package/public/index.css +34 -7
- package/public/index.html +7 -0
- package/public/index.js +715 -210
- package/public/index.js.map +1 -1
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sources":["../src/module/render-html.ts","../src/module/index.ts"],"sourcesContent":["import css from '../../public/index.css';\nimport html from '../../public/index.html';\nimport js from '../../public/index.js';\nimport type { ViewerAssets } from '../options';\n\n/**\n * Asset urls and settings the embedder supplies to the viewer. The asset urls are the same\n * fields `createViewer` takes in a page ({@link ViewerAssets}); here every one is optional,\n * because the document has a default for each.\n *\n * Url params on the served page take precedence over every url here, so an embed stays\n * overridable per instance. Inline {@link ViewerBootstrap.settings} is the exception: it wins\n * over `?settings=`, so a published experience cannot be repointed at another settings file.\n * `contentFilename` is ignored when a `?content=` param overrides the url it describes.\n */\ntype ViewerBootstrap = Partial<ViewerAssets> & {\n /**\n * Experience settings as an object, avoiding a round trip. When omitted the viewer\n * fetches {@link ViewerBootstrap.settingsUrl}.\n */\n settings?: unknown;\n /** Where to fetch settings from. Defaults to `./settings.json`. */\n settingsUrl?: string;\n};\n\n/** Options for {@link renderViewerHtml}. */\ntype RenderViewerHtmlOptions = {\n /** Asset urls and settings for the viewer to boot with. */\n bootstrap?: ViewerBootstrap;\n /** Value for the document's `<base href>`, for a viewer served from a sub-path. */\n baseHref?: string;\n /**\n * Page background, applied before the first frame renders to avoid a flash. Components\n * are normalized 0..1, not 0..255, matching `background.color` in the settings format —\n * so an experience's own colour can be passed straight through.\n */\n backgroundColor?: readonly [number, number, number];\n /** Raw markup injected before `</head>`, for analytics or error reporting. */\n headExtras?: string;\n /**\n * Raw markup injected immediately after `<body>`, for content that must precede the\n * canvas — a marker element a screenshot pipeline waits on, for example.\n */\n bodyStartExtras?: string;\n /** Inline the stylesheet into a `<style>` block instead of linking `./index.css`. */\n inlineCss?: boolean;\n /**\n * Inline the module bundle instead of importing `./index.js`. Independent of\n * {@link RenderViewerHtmlOptions.inlineCss}: a host serving the bundle from its own route\n * wants the css inlined to avoid a round trip before first paint, but not a megabyte of\n * js in every page.\n */\n inlineJs?: boolean;\n};\n\ntype Replacer = (match: string, ...groups: string[]) => string;\n\n// The seams below are matched against this package's own `index.html`, so a miss means the\n// document and this function have drifted apart within one release — a build-time invariant,\n// not a bad caller. Throw rather than return a half-rendered document.\n//\n// Every replacement is a function, so `$&`-style sequences in settings json, urls or the\n// bundle are inserted literally instead of being interpreted as replacement patterns.\n// Annotation text is user-authored, so this matters.\nconst replaceOnce = (source: string, pattern: RegExp, replacement: Replacer) => {\n if (!pattern.test(source)) {\n throw new Error(`renderViewerHtml: no match for ${String(pattern)} in the viewer html`);\n }\n return source.replace(pattern, replacement);\n};\n\n// Serialize for embedding in a `<script type=\"application/json\">` block. Every `<` is\n// escaped with its json unicode escape (so the payload round-trips byte-exact), which\n// neutralises all of the parser's script-content hazards at once: `</script` ending\n// the block early, and `<!--` followed by `<script` switching the tokenizer into the\n// double-escaped state, where the block's own close tag is consumed as text and the rest of\n// the document is swallowed. U+2028/U+2029 are escaped because they are legal in json\n// strings but terminate a line in some js parsers.\nconst jsonForScriptBlock = (value: unknown) => {\n return JSON.stringify(value)\n .replace(/</g, '\\\\u003c')\n .replace(/\\u2028/g, '\\\\u2028')\n .replace(/\\u2029/g, '\\\\u2029');\n};\n\n// Escape for use inside a double-quoted html attribute. `headExtras` is documented as raw\n// markup and is deliberately not escaped, but scalar options like `baseHref` are not an\n// injection channel and a caller passing one through from user input should be safe.\nconst escapeAttribute = (value: string) => {\n return value.replace(/&/g, '&').replace(/\"/g, '"').replace(/</g, '<').replace(/>/g, '>');\n};\n\nconst indent = (text: string, spaces: number) => {\n const whitespace = ' '.repeat(spaces);\n return text\n .split('\\n')\n .map((line) => whitespace + line)\n .join('\\n');\n};\n\nconst BOOTSTRAP = /<script type=\"application\\/json\" id=\"sse-bootstrap\">[\\s\\S]*?<\\/script>/;\nconst BASE_HREF = /<base\\b[^>]*>/;\nconst STYLESHEET = /<link\\b[^>]*href=\"\\.\\/index\\.css\"[^>]*>/;\nconst MODULE_IMPORT = /import \\{ createViewer \\} from '\\.\\/index\\.js';/;\nconst HEAD_CLOSE = /^([ \\t]*)<\\/head>/m;\nconst BODY_OPEN = /<body\\b[^>]*>/;\n\n/**\n * Render a standalone viewer document.\n *\n * This is the supported way to embed the viewer in a page you generate. Called with no\n * options it returns the document this package ships, unmodified.\n *\n * @param options - Embedding options; see {@link RenderViewerHtmlOptions}.\n * @returns The rendered html document.\n */\nconst renderViewerHtml = (options: RenderViewerHtmlOptions = {}) => {\n const { bootstrap, baseHref, backgroundColor, headExtras, bodyStartExtras, inlineCss, inlineJs } = options;\n\n let result = html;\n\n // Order matters. Each seam is matched with a non-global regex, so the *first* occurrence\n // in the document wins — and caller-controlled content (the bootstrap json, `headExtras`)\n // can contain text that looks like a seam. Settings carry user-authored annotation text,\n // so treat that as hostile. Every seam is therefore replaced before any caller content is\n // inserted, and the two insertions go last, in document order.\n\n if (baseHref !== undefined) {\n result = replaceOnce(result, BASE_HREF, () => `<base href=\"${escapeAttribute(baseHref)}\">`);\n }\n\n if (inlineCss) {\n // A `<style>` element is rawtext: it ends at the first `</style` regardless of css\n // syntax, so a stylesheet containing that sequence cannot be inlined. The built css\n // contains no `<` at all today; fail loudly if that ever changes.\n if (/<\\/style/i.test(css)) {\n throw new Error('renderViewerHtml: the viewer stylesheet contains \"</style\" and cannot be inlined');\n }\n result = replaceOnce(result, STYLESHEET, () => `<style>\\n${indent(css, 12)}\\n </style>`);\n }\n\n if (inlineJs) {\n // The bundle's trailing sourceMappingURL comment points at a sibling index.js.map\n // that an inlined document does not sit next to, so devtools would 404 on it (or\n // bind whatever stranger's map the host serves at that path).\n const inlineJsSource = js.replace(/\\n\\/\\/# sourceMappingURL=\\S+\\s*$/, '\\n');\n\n // An inline module script ends at the first `</script`, and `<!--` followed by\n // `<script` switches the tokenizer into a state where that close tag is consumed as\n // text instead — either way the symptom is an exported file that renders nothing.\n // The bundle contains none of these today; fail loudly if that ever changes.\n // Case-insensitive, because the html parser is.\n if (/<\\/script|<!--|<script/i.test(inlineJsSource)) {\n throw new Error(\n 'renderViewerHtml: the viewer bundle contains markup the html parser acts on and cannot be inlined'\n );\n }\n result = replaceOnce(result, MODULE_IMPORT, () => inlineJsSource);\n }\n\n if (bodyStartExtras !== undefined) {\n result = replaceOnce(result, BODY_OPEN, (bodyTag) => `${bodyTag}\\n ${bodyStartExtras}`);\n }\n\n const headAppend: string[] = [];\n if (headExtras !== undefined) {\n headAppend.push(headExtras);\n }\n if (backgroundColor) {\n const rgb = backgroundColor.map((c) => Math.round(c * 255)).join(', ');\n headAppend.push(`<style>body { background-color: rgb(${rgb}); }</style>`);\n }\n\n // Emitted at the end of head, so the background rule wins over the stylesheet on equal\n // specificity. Only the first line gains indentation: `headExtras` is raw markup, and\n // reindenting its interior lines would rewrite whitespace-sensitive content (a template\n // literal in an inline script, for instance).\n if (headAppend.length > 0) {\n result = replaceOnce(result, HEAD_CLOSE, (_match, ws) => `${ws} ${headAppend.join('\\n')}\\n${ws}</head>`);\n }\n\n // Last: the bootstrap block sits earlier in the document than `</head>`, so its own seam\n // still matches ahead of anything `headExtras` added.\n if (bootstrap) {\n const json = jsonForScriptBlock(bootstrap);\n result = replaceOnce(\n result,\n BOOTSTRAP,\n () => `<script type=\"application/json\" id=\"sse-bootstrap\">${json}</script>`\n );\n }\n\n return result;\n};\n\nexport type { RenderViewerHtmlOptions, ViewerBootstrap };\nexport { renderViewerHtml };\n","import cssSource from '../../public/index.css';\nimport htmlSource from '../../public/index.html';\nimport jsSource from '../../public/index.js';\n\n/**\n * The viewer's html document.\n *\n * @deprecated Use {@link renderViewerHtml} instead. Pattern-matching this string is\n * unsupported — its formatting is not part of this package's api and changes between\n * releases.\n */\nconst html: string = htmlSource;\n\n/** The viewer's stylesheet, for serving alongside a rendered document. */\nconst css: string = cssSource;\n\n/** The viewer's module bundle, for serving alongside a rendered document. */\nconst js: string = jsSource;\n\nexport type { ViewerAssets } from '../options';\nexport type { RenderViewerHtmlOptions, ViewerBootstrap } from './render-html';\nexport { renderViewerHtml } from './render-html';\n\nexport { html, css, js };\n"],"names":["html","css","js"],"mappings":";;;;;;AAyDA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,MAAM,WAAW,GAAG,CAAC,MAAc,EAAE,OAAe,EAAE,WAAqB,KAAI;IAC3E,IAAI,CAAC,OAAO,CAAC,IAAI,CAAC,MAAM,CAAC,EAAE;QACvB,MAAM,IAAI,KAAK,CAAC,CAAA,+BAAA,EAAkC,MAAM,CAAC,OAAO,CAAC,CAAA,mBAAA,CAAqB,CAAC;IAC3F;IACA,OAAO,MAAM,CAAC,OAAO,CAAC,OAAO,EAAE,WAAW,CAAC;AAC/C,CAAC;AAED;AACA;AACA;AACA;AACA;AACA;AACA;AACA,MAAM,kBAAkB,GAAG,CAAC,KAAc,KAAI;AAC1C,IAAA,OAAO,IAAI,CAAC,SAAS,CAAC,KAAK;AACtB,SAAA,OAAO,CAAC,IAAI,EAAE,SAAS;AACvB,SAAA,OAAO,CAAC,SAAS,EAAE,SAAS;AAC5B,SAAA,OAAO,CAAC,SAAS,EAAE,SAAS,CAAC;AACtC,CAAC;AAED;AACA;AACA;AACA,MAAM,eAAe,GAAG,CAAC,KAAa,KAAI;AACtC,IAAA,OAAO,KAAK,CAAC,OAAO,CAAC,IAAI,EAAE,OAAO,CAAC,CAAC,OAAO,CAAC,IAAI,EAAE,QAAQ,CAAC,CAAC,OAAO,CAAC,IAAI,EAAE,MAAM,CAAC,CAAC,OAAO,C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ACN,SAAS,EACT,MAAM,CAAA,mDAAA,EAAsD,IAAI,CAAA,SAAA,CAAW,CAC9E;IACL;AAEA,IAAA,OAAO,MAAM;AACjB;;AC7LA;;;;;;AAMG;AACH,MAAM,IAAI,GAAW;AAErB;AACA,MAAM,GAAG,GAAW;AAEpB;AACA,MAAM,EAAE,GAAW;;"}
|
|
1
|
+
{"version":3,"file":"index.js","sources":["../src/module/render-html.ts","../src/module/index.ts"],"sourcesContent":["import css from '../../public/index.css';\nimport html from '../../public/index.html';\nimport js from '../../public/index.js';\nimport type { ViewerAssets } from '../options';\n\n/**\n * Asset urls and settings the embedder supplies to the viewer. The asset urls are the same\n * fields `createViewer` takes in a page ({@link ViewerAssets}); here every one is optional,\n * because the document has a default for each.\n *\n * Url params on the served page take precedence over every url here, so an embed stays\n * overridable per instance. Inline {@link ViewerBootstrap.settings} is the exception: it wins\n * over `?settings=`, so a published experience cannot be repointed at another settings file.\n * `contentFilename` is ignored when a `?content=` param overrides the url it describes.\n */\ntype ViewerBootstrap = Partial<ViewerAssets> & {\n /**\n * Experience settings as an object, avoiding a round trip. When omitted the viewer\n * fetches {@link ViewerBootstrap.settingsUrl}.\n */\n settings?: unknown;\n /** Where to fetch settings from. Defaults to `./settings.json`. */\n settingsUrl?: string;\n};\n\n/** Options for {@link renderViewerHtml}. */\ntype RenderViewerHtmlOptions = {\n /** Asset urls and settings for the viewer to boot with. */\n bootstrap?: ViewerBootstrap;\n /** Value for the document's `<base href>`, for a viewer served from a sub-path. */\n baseHref?: string;\n /**\n * Page background, applied before the first frame renders to avoid a flash. Components\n * are normalized 0..1, not 0..255, matching `background.color` in the settings format —\n * so an experience's own colour can be passed straight through.\n */\n backgroundColor?: readonly [number, number, number];\n /** Raw markup injected before `</head>`, for analytics or error reporting. */\n headExtras?: string;\n /**\n * Raw markup injected immediately after `<body>`, for content that must precede the\n * canvas — a marker element a screenshot pipeline waits on, for example.\n */\n bodyStartExtras?: string;\n /** Inline the stylesheet into a `<style>` block instead of linking `./index.css`. */\n inlineCss?: boolean;\n /**\n * Inline the module bundle instead of importing `./index.js`. Independent of\n * {@link RenderViewerHtmlOptions.inlineCss}: a host serving the bundle from its own route\n * wants the css inlined to avoid a round trip before first paint, but not a megabyte of\n * js in every page.\n */\n inlineJs?: boolean;\n};\n\ntype Replacer = (match: string, ...groups: string[]) => string;\n\n// The seams below are matched against this package's own `index.html`, so a miss means the\n// document and this function have drifted apart within one release — a build-time invariant,\n// not a bad caller. Throw rather than return a half-rendered document.\n//\n// Every replacement is a function, so `$&`-style sequences in settings json, urls or the\n// bundle are inserted literally instead of being interpreted as replacement patterns.\n// Annotation text is user-authored, so this matters.\nconst replaceOnce = (source: string, pattern: RegExp, replacement: Replacer) => {\n if (!pattern.test(source)) {\n throw new Error(`renderViewerHtml: no match for ${String(pattern)} in the viewer html`);\n }\n return source.replace(pattern, replacement);\n};\n\n// Serialize for embedding in a `<script type=\"application/json\">` block. Every `<` is\n// escaped with its json unicode escape (so the payload round-trips byte-exact), which\n// neutralises all of the parser's script-content hazards at once: `</script` ending\n// the block early, and `<!--` followed by `<script` switching the tokenizer into the\n// double-escaped state, where the block's own close tag is consumed as text and the rest of\n// the document is swallowed. U+2028/U+2029 are escaped because they are legal in json\n// strings but terminate a line in some js parsers.\nconst jsonForScriptBlock = (value: unknown) => {\n return JSON.stringify(value)\n .replace(/</g, '\\\\u003c')\n .replace(/\\u2028/g, '\\\\u2028')\n .replace(/\\u2029/g, '\\\\u2029');\n};\n\n// Escape for use inside a double-quoted html attribute. `headExtras` is documented as raw\n// markup and is deliberately not escaped, but scalar options like `baseHref` are not an\n// injection channel and a caller passing one through from user input should be safe.\nconst escapeAttribute = (value: string) => {\n return value.replace(/&/g, '&').replace(/\"/g, '"').replace(/</g, '<').replace(/>/g, '>');\n};\n\nconst indent = (text: string, spaces: number) => {\n const whitespace = ' '.repeat(spaces);\n return text\n .split('\\n')\n .map((line) => whitespace + line)\n .join('\\n');\n};\n\nconst BOOTSTRAP = /<script type=\"application\\/json\" id=\"sse-bootstrap\">[\\s\\S]*?<\\/script>/;\nconst BASE_HREF = /<base\\b[^>]*>/;\nconst STYLESHEET = /<link\\b[^>]*href=\"\\.\\/index\\.css\"[^>]*>/;\nconst MODULE_IMPORT = /import \\{ createViewer \\} from '\\.\\/index\\.js';/;\nconst HEAD_CLOSE = /^([ \\t]*)<\\/head>/m;\nconst BODY_OPEN = /<body\\b[^>]*>/;\n\n/**\n * Render a standalone viewer document.\n *\n * This is the supported way to embed the viewer in a page you generate. Called with no\n * options it returns the document this package ships, unmodified.\n *\n * @param options - Embedding options; see {@link RenderViewerHtmlOptions}.\n * @returns The rendered html document.\n */\nconst renderViewerHtml = (options: RenderViewerHtmlOptions = {}) => {\n const { bootstrap, baseHref, backgroundColor, headExtras, bodyStartExtras, inlineCss, inlineJs } = options;\n\n let result = html;\n\n // Order matters. Each seam is matched with a non-global regex, so the *first* occurrence\n // in the document wins — and caller-controlled content (the bootstrap json, `headExtras`)\n // can contain text that looks like a seam. Settings carry user-authored annotation text,\n // so treat that as hostile. Every seam is therefore replaced before any caller content is\n // inserted, and the two insertions go last, in document order.\n\n if (baseHref !== undefined) {\n result = replaceOnce(result, BASE_HREF, () => `<base href=\"${escapeAttribute(baseHref)}\">`);\n }\n\n if (inlineCss) {\n // A `<style>` element is rawtext: it ends at the first `</style` regardless of css\n // syntax, so a stylesheet containing that sequence cannot be inlined. The built css\n // contains no `<` at all today; fail loudly if that ever changes.\n if (/<\\/style/i.test(css)) {\n throw new Error('renderViewerHtml: the viewer stylesheet contains \"</style\" and cannot be inlined');\n }\n result = replaceOnce(result, STYLESHEET, () => `<style>\\n${indent(css, 12)}\\n </style>`);\n }\n\n if (inlineJs) {\n // The bundle's trailing sourceMappingURL comment points at a sibling index.js.map\n // that an inlined document does not sit next to, so devtools would 404 on it (or\n // bind whatever stranger's map the host serves at that path).\n const inlineJsSource = js.replace(/\\n\\/\\/# sourceMappingURL=\\S+\\s*$/, '\\n');\n\n // An inline module script ends at the first `</script`, and `<!--` followed by\n // `<script` switches the tokenizer into a state where that close tag is consumed as\n // text instead — either way the symptom is an exported file that renders nothing.\n // The bundle contains none of these today; fail loudly if that ever changes.\n // Case-insensitive, because the html parser is.\n if (/<\\/script|<!--|<script/i.test(inlineJsSource)) {\n throw new Error(\n 'renderViewerHtml: the viewer bundle contains markup the html parser acts on and cannot be inlined'\n );\n }\n result = replaceOnce(result, MODULE_IMPORT, () => inlineJsSource);\n }\n\n if (bodyStartExtras !== undefined) {\n result = replaceOnce(result, BODY_OPEN, (bodyTag) => `${bodyTag}\\n ${bodyStartExtras}`);\n }\n\n const headAppend: string[] = [];\n if (headExtras !== undefined) {\n headAppend.push(headExtras);\n }\n if (backgroundColor) {\n const rgb = backgroundColor.map((c) => Math.round(c * 255)).join(', ');\n headAppend.push(`<style>body { background-color: rgb(${rgb}); }</style>`);\n }\n\n // Emitted at the end of head, so the background rule wins over the stylesheet on equal\n // specificity. Only the first line gains indentation: `headExtras` is raw markup, and\n // reindenting its interior lines would rewrite whitespace-sensitive content (a template\n // literal in an inline script, for instance).\n if (headAppend.length > 0) {\n result = replaceOnce(result, HEAD_CLOSE, (_match, ws) => `${ws} ${headAppend.join('\\n')}\\n${ws}</head>`);\n }\n\n // Last: the bootstrap block sits earlier in the document than `</head>`, so its own seam\n // still matches ahead of anything `headExtras` added.\n if (bootstrap) {\n const json = jsonForScriptBlock(bootstrap);\n result = replaceOnce(\n result,\n BOOTSTRAP,\n () => `<script type=\"application/json\" id=\"sse-bootstrap\">${json}</script>`\n );\n }\n\n return result;\n};\n\nexport type { RenderViewerHtmlOptions, ViewerBootstrap };\nexport { renderViewerHtml };\n","import cssSource from '../../public/index.css';\nimport htmlSource from '../../public/index.html';\nimport jsSource from '../../public/index.js';\n\n/**\n * The viewer's html document.\n *\n * @deprecated Use {@link renderViewerHtml} instead. Pattern-matching this string is\n * unsupported — its formatting is not part of this package's api and changes between\n * releases.\n */\nconst html: string = htmlSource;\n\n/** The viewer's stylesheet, for serving alongside a rendered document. */\nconst css: string = cssSource;\n\n/** The viewer's module bundle, for serving alongside a rendered document. */\nconst js: string = jsSource;\n\nexport type { ViewerAssets, ViewerFlags } from '../options';\nexport type { RenderViewerHtmlOptions, ViewerBootstrap } from './render-html';\nexport { renderViewerHtml } from './render-html';\n\nexport { html, css, js };\n"],"names":["html","css","js"],"mappings":";;;;;;AAyDA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,MAAM,WAAW,GAAG,CAAC,MAAc,EAAE,OAAe,EAAE,WAAqB,KAAI;IAC3E,IAAI,CAAC,OAAO,CAAC,IAAI,CAAC,MAAM,CAAC,EAAE;QACvB,MAAM,IAAI,KAAK,CAAC,CAAA,+BAAA,EAAkC,MAAM,CAAC,OAAO,CAAC,CAAA,mBAAA,CAAqB,CAAC;IAC3F;IACA,OAAO,MAAM,CAAC,OAAO,CAAC,OAAO,EAAE,WAAW,CAAC;AAC/C,CAAC;AAED;AACA;AACA;AACA;AACA;AACA;AACA;AACA,MAAM,kBAAkB,GAAG,CAAC,KAAc,KAAI;AAC1C,IAAA,OAAO,IAAI,CAAC,SAAS,CAAC,KAAK;AACtB,SAAA,OAAO,CAAC,IAAI,EAAE,SAAS;AACvB,SAAA,OAAO,CAAC,SAAS,EAAE,SAAS;AAC5B,SAAA,OAAO,CAAC,SAAS,EAAE,SAAS,CAAC;AACtC,CAAC;AAED;AACA;AACA;AACA,MAAM,eAAe,GAAG,CAAC,KAAa,KAAI;AACtC,IAAA,OAAO,KAAK,CAAC,OAAO,CAAC,IAAI,EAAE,OAAO,CAAC,CAAC,OAAO,CAAC,IAAI,EAAE,QAAQ,CAAC,CAAC,OAAO,CAAC,IAAI,EAAE,MAAM,CAAC,CAAC,OAAO,CAAC,IAAI,EAAE,MAAM,CAAC;AAC3G,CAAC;AAED,MAAM,MAAM,GAAG,CAAC,IAAY,EAAE,MAAc,KAAI;IAC5C,MAAM,UAAU,GAAG,GAAG,CAAC,MAAM,CAAC,MAAM,CAAC;AACrC,IAAA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GAAG,GAAW;AAEpB;AACA,MAAM,EAAE,GAAW;;"}
|
package/dist/viewer.css
CHANGED
|
@@ -11,6 +11,14 @@
|
|
|
11
11
|
--sse-bkg-darkest: #141414;
|
|
12
12
|
--sse-bkg-light: #444;
|
|
13
13
|
--canvas-opacity: 1;
|
|
14
|
+
--sse-lift: 0px;
|
|
15
|
+
}
|
|
16
|
+
@media (pointer: coarse) {
|
|
17
|
+
.sse-viewer {
|
|
18
|
+
--sse-lift: var(--sse-experimental-touch-inset-bottom, 0px);
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
.sse-viewer {
|
|
14
22
|
position: relative;
|
|
15
23
|
width: 100%;
|
|
16
24
|
height: 100%;
|
|
@@ -130,10 +138,19 @@
|
|
|
130
138
|
.sse-viewer .sse-controlsHint {
|
|
131
139
|
position: absolute;
|
|
132
140
|
right: max(16px, env(safe-area-inset-right));
|
|
133
|
-
bottom: calc(max(16px, env(safe-area-inset-bottom)) + 70px);
|
|
141
|
+
bottom: calc(max(16px, env(safe-area-inset-bottom)) + 70px + var(--sse-lift));
|
|
142
|
+
max-height: calc(100% - 16px - calc(max(16px, env(safe-area-inset-bottom)) + 70px + var(--sse-lift)));
|
|
143
|
+
box-sizing: border-box;
|
|
144
|
+
overflow-y: auto;
|
|
145
|
+
overscroll-behavior: contain;
|
|
146
|
+
}
|
|
147
|
+
.sse-viewer .sse-controlsHint,
|
|
148
|
+
.sse-viewer .sse-controlsHint * {
|
|
149
|
+
touch-action: pan-y;
|
|
150
|
+
}
|
|
151
|
+
.sse-viewer .sse-controlsHint {
|
|
134
152
|
min-width: 200px;
|
|
135
153
|
max-width: calc(100% - 32px);
|
|
136
|
-
box-sizing: border-box;
|
|
137
154
|
padding: 8px 8px 8px 12px;
|
|
138
155
|
border-radius: 16px;
|
|
139
156
|
border: 1px solid rgba(255, 255, 255, 0.08);
|
|
@@ -307,7 +324,7 @@
|
|
|
307
324
|
}
|
|
308
325
|
.sse-viewer .sse-loadingWrap {
|
|
309
326
|
position: absolute;
|
|
310
|
-
bottom: 120px;
|
|
327
|
+
bottom: calc(120px + var(--sse-lift));
|
|
311
328
|
left: 50%;
|
|
312
329
|
transform: translate(-50%, 0);
|
|
313
330
|
width: min(380px, 100% - 32px);
|
|
@@ -335,7 +352,7 @@
|
|
|
335
352
|
position: absolute;
|
|
336
353
|
left: max(16px, env(safe-area-inset-left));
|
|
337
354
|
right: max(16px, env(safe-area-inset-right));
|
|
338
|
-
bottom: max(16px, env(safe-area-inset-bottom));
|
|
355
|
+
bottom: calc(max(16px, env(safe-area-inset-bottom)) + var(--sse-lift));
|
|
339
356
|
display: flex;
|
|
340
357
|
flex-direction: column;
|
|
341
358
|
}
|
|
@@ -467,7 +484,17 @@
|
|
|
467
484
|
.sse-viewer .sse-settingsPanel {
|
|
468
485
|
position: absolute;
|
|
469
486
|
right: max(16px, env(safe-area-inset-right));
|
|
470
|
-
bottom: calc(max(16px, env(safe-area-inset-bottom)) + 70px);
|
|
487
|
+
bottom: calc(max(16px, env(safe-area-inset-bottom)) + 70px + var(--sse-lift));
|
|
488
|
+
max-height: calc(100% - 16px - calc(max(16px, env(safe-area-inset-bottom)) + 70px + var(--sse-lift)));
|
|
489
|
+
box-sizing: border-box;
|
|
490
|
+
overflow-y: auto;
|
|
491
|
+
overscroll-behavior: contain;
|
|
492
|
+
}
|
|
493
|
+
.sse-viewer .sse-settingsPanel,
|
|
494
|
+
.sse-viewer .sse-settingsPanel * {
|
|
495
|
+
touch-action: pan-y;
|
|
496
|
+
}
|
|
497
|
+
.sse-viewer .sse-settingsPanel {
|
|
471
498
|
padding: 12px;
|
|
472
499
|
border-radius: 16px;
|
|
473
500
|
border: 1px solid rgba(255, 255, 255, 0.08);
|
|
@@ -763,7 +790,7 @@
|
|
|
763
790
|
.sse-viewer .sse-joystickBase {
|
|
764
791
|
position: absolute;
|
|
765
792
|
left: 70px;
|
|
766
|
-
bottom: 140px;
|
|
793
|
+
bottom: calc(140px + var(--sse-lift));
|
|
767
794
|
width: 56px;
|
|
768
795
|
height: 100px;
|
|
769
796
|
transform: translate(-50%, 50%);
|
|
@@ -915,7 +942,7 @@
|
|
|
915
942
|
.sse-viewer .sse-xrHint {
|
|
916
943
|
position: absolute;
|
|
917
944
|
left: 50%;
|
|
918
|
-
bottom: 96px;
|
|
945
|
+
bottom: calc(96px + var(--sse-lift));
|
|
919
946
|
transform: translateX(-50%);
|
|
920
947
|
padding: 12px 20px;
|
|
921
948
|
border-radius: 20px;
|
package/dist/viewer.d.ts
CHANGED
|
@@ -37,6 +37,14 @@ type ViewerFlags = {
|
|
|
37
37
|
* fallback prompt live in that ui, so a headless host owns those affordances too.
|
|
38
38
|
*/
|
|
39
39
|
ui?: boolean;
|
|
40
|
+
/**
|
|
41
|
+
* Css pixels by which the toolbar, and everything else anchored to the viewer's bottom edge,
|
|
42
|
+
* is lifted, so chrome a host app draws over the bottom of the viewer does not cover it. On
|
|
43
|
+
* touch devices (a coarse primary pointer) only; elsewhere the toolbar stays at the edge.
|
|
44
|
+
* Clamped to 0–200. Defaults to `0`. Experimental: it may be renamed or removed in a minor
|
|
45
|
+
* release.
|
|
46
|
+
*/
|
|
47
|
+
experimentalTouchInsetBottom?: number;
|
|
40
48
|
/** Show the centre reticle in desktop fly/walk mode with gaming controls. Defaults to `false`. */
|
|
41
49
|
reticle?: boolean;
|
|
42
50
|
/** Start with the camera animation paused. */
|
|
@@ -62,13 +70,13 @@ type ViewerFlags = {
|
|
|
62
70
|
/** Render with antialiasing. */
|
|
63
71
|
aa?: boolean;
|
|
64
72
|
/**
|
|
65
|
-
* Developer override of the
|
|
66
|
-
* (unsorted, depth-tested splats whose depth buffer also serves picking) in its
|
|
67
|
-
* mode, `'mobile'` in its interleaved-pixel-sets mode, and `'off'`
|
|
68
|
-
*
|
|
69
|
-
* device class picks the mode. WebGPU only; ignored on WebGL. The
|
|
70
|
-
* sessions too, one view per eye (Safari on Apple Vision Pro); where
|
|
71
|
-
* session, the viewer offers a reload into WebGL.
|
|
73
|
+
* Developer override of the Performance Mode setting: `true` forces the stochastic splat
|
|
74
|
+
* renderer (unsorted, depth-tested splats whose depth buffer also serves picking) in its
|
|
75
|
+
* per-pixel mode, `'mobile'` in its interleaved-pixel-sets mode, and `'off'` keeps the
|
|
76
|
+
* engine's sorted renderer; each hides the setting. Without it the user's Performance Mode
|
|
77
|
+
* toggle decides, and the device class picks the mode. WebGPU only; ignored on WebGL. The
|
|
78
|
+
* renderer draws WebGPU XR sessions too, one view per eye (Safari on Apple Vision Pro); where
|
|
79
|
+
* only WebGL could host a session, the viewer offers a reload into WebGL.
|
|
72
80
|
*/
|
|
73
81
|
stochastic?: boolean | 'mobile' | 'off';
|
|
74
82
|
/**
|