@playcanvas/supersplat-viewer 1.31.2 → 1.33.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/README.md +3 -171
- package/dist/index.d.ts +28 -18
- package/dist/index.js +4 -4
- package/dist/index.js.map +1 -1
- package/dist/viewer.css +761 -0
- package/dist/viewer.d.ts +274 -0
- package/dist/viewer.js +11471 -0
- package/dist/viewer.js.map +1 -0
- package/docs/api.md +356 -0
- package/package.json +20 -6
- package/public/index.css +221 -211
- package/public/index.html +40 -618
- package/public/index.js +2697 -1610
- 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';\n\n/**\n * Asset urls and settings the embedder supplies to the viewer.\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 */\ntype ViewerBootstrap = {\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 /** Splat url. May be a `data:` uri, for a document with no sibling files. */\n contentUrl?: string;\n /**\n * Filename describing {@link ViewerBootstrap.contentUrl}, e.g. `scene.sog`. The splat\n * format is chosen by the name's extension, so this is required when the url itself has\n * no usable name — a `data:` uri. Ignored when a `?content=` url param overrides the url\n * it describes.\n */\n contentFilename?: string;\n /** Poster image shown, blurred, while the splat loads. */\n posterUrl?: string;\n /** Equirectangular skybox texture url. */\n skyboxUrl?: string;\n /** Collision data url, for walk mode. A `.glb` is treated as a mesh, otherwise voxels. */\n collisionUrl?: 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 \\{ main \\} 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 { RenderViewerHtmlOptions, ViewerBootstrap } from './render-html';\nexport { renderViewerHtml } from './render-html';\n\nexport { html, css, js };\n"],"names":["html","css","js"],"mappings":";;;;;;AAoEA;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;A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AAC,IAAI,CAAC,IAAI,CAAC,CAAA,EAAA,EAAK,EAAE,CAAA,OAAA,CAAS,CAAC;IAC/G;;;IAIA,IAAI,SAAS,EAAE;AACX,QAAA,MAAM,IAAI,GAAG,kBAAkB,CAAC,SAAS,CAAC;AAC1C,QAAA,MAAM,GAAG,WAAW,CAChB,MAAM,EACN,SAAS,EACT,MAAM,CAAA,mDAAA,EAAsD,IAAI,CAAA,SAAA,CAAW,CAC9E;IACL;AAEA,IAAA,OAAO,MAAM;AACjB;;ACxMA;;;;;;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 } 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,IAA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