-
-
Notifications
You must be signed in to change notification settings - Fork 6.9k
Frontend iframe renderer framework: 3D models, OpenAPI #37233
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
+540
−293
Merged
Changes from 1 commit
Commits
Show all changes
39 commits
Select commit
Hold shift + click to select a range
73659e4
Render 3d models into iframe
silverwind 76b22d9
fine tune
wxiaoguang 28ff9e5
fix comment
wxiaoguang 2780dc4
Move 3D iframe rendering to frontend
silverwind 2bd893e
Remove dash from viewer-3d naming
silverwind 8eaf95c
Restore explicit edgeSettings
silverwind 5ce09dd
Integrate 3D plugin with external-render framework
silverwind a234c1b
Revert to backend-rendered 3D viewer
silverwind dbf71b9
Merge branch 'main' into 3diframe
wxiaoguang a149a1c
refactor
wxiaoguang 40f7a9b
lazy load
wxiaoguang 72f2736
add comment
wxiaoguang 5f18aba
Fix iframe content corruption and ref double-escape
silverwind cd9cc52
Surface plugin errors via console.error
silverwind 2a99783
Add e2e regression test for asciicast on non-ASCII branch
silverwind 49b0cb9
Merge branch 'main' into 3diframe
silverwind 1c882f4
Remove obsolete test, covered by e2e
silverwind f259edd
Apply suggestion from @silverwind
silverwind b85c711
add comment and TODO
wxiaoguang 7487d79
revert wrongly deleted comment
wxiaoguang 78e11b3
add more comments
wxiaoguang 23eb19b
Fix 3D viewer collapsed-iframe regression, expand e2e
silverwind 42070d9
remove iframe window margin/padding
wxiaoguang c1e33ed
remove markup class for iframe render
wxiaoguang e6d8a45
Assert iframe/container height for asciicast and openapi e2e
silverwind 9002c44
Fix TestRenderIFrame after data-global-init addition
silverwind 80b3db8
fix sandboxed console error
wxiaoguang 4499460
fix border radius
wxiaoguang 7900812
Expand openapi e2e to exercise swagger-ui $ref resolver
silverwind 1e44f97
fix lint
wxiaoguang 00f73ec
Fix swagger pushState in srcdoc iframe, lint and quality cleanup
silverwind 942292c
Revert arrow simplification in lazy plugin loaders
silverwind 28bea73
Merge branch 'main' into 3diframe
silverwind 95d1797
add comment
wxiaoguang 782cb42
fix render query params
wxiaoguang adfa063
Merge branch 'main' into 3diframe
silverwind c1c7354
Add e2e assertions for renderer padding and 3D bgcolor
silverwind 3372b59
Merge branch 'main' into 3diframe
GiteaBot 81700d9
Avoid non-null assertions on boundingBox in assertFlushWithParent
silverwind File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Some comments aren't visible on the classic Files Changed page.
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,79 @@ | ||
| // Copyright 2026 The Gitea Authors. All rights reserved. | ||
| // SPDX-License-Identifier: MIT | ||
|
|
||
| package external | ||
|
|
||
| import ( | ||
| "encoding/base64" | ||
| "fmt" | ||
| "html" | ||
| "io" | ||
| "path" | ||
|
|
||
| "code.gitea.io/gitea/modules/markup" | ||
| "code.gitea.io/gitea/modules/public" | ||
| "code.gitea.io/gitea/modules/setting" | ||
| ) | ||
|
|
||
| type viewer3dRenderer struct{} | ||
|
|
||
| var ( | ||
| _ markup.PostProcessRenderer = (*viewer3dRenderer)(nil) | ||
| _ markup.ExternalRenderer = (*viewer3dRenderer)(nil) | ||
| ) | ||
|
|
||
| func (p *viewer3dRenderer) Name() string { | ||
| return "viewer3d" | ||
| } | ||
|
|
||
| func (p *viewer3dRenderer) NeedPostProcess() bool { | ||
| return false | ||
| } | ||
|
|
||
| func (p *viewer3dRenderer) FileNamePatterns() []string { | ||
| return []string{ | ||
| "*.3dm", "*.3ds", "*.3mf", "*.amf", "*.bim", "*.brep", | ||
| "*.dae", "*.fbx", "*.fcstd", "*.glb", "*.gltf", | ||
| "*.ifc", "*.igs", "*.iges", "*.stp", "*.step", | ||
| "*.stl", "*.obj", "*.off", "*.ply", "*.wrl", | ||
| } | ||
| } | ||
|
|
||
| func (p *viewer3dRenderer) SanitizerRules() []setting.MarkupSanitizerRule { | ||
| return nil | ||
| } | ||
|
|
||
| func (p *viewer3dRenderer) GetExternalRendererOptions() (ret markup.ExternalRendererOptions) { | ||
| ret.SanitizerDisabled = true | ||
| ret.DisplayInIframe = true | ||
| ret.ContentSandbox = "allow-scripts" | ||
| return ret | ||
| } | ||
|
|
||
| func (p *viewer3dRenderer) Render(ctx *markup.RenderContext, input io.Reader, output io.Writer) error { | ||
| if ctx.RenderOptions.StandalonePageOptions == nil { | ||
| opts := p.GetExternalRendererOptions() | ||
| return markup.RenderIFrame(ctx, &opts, output) | ||
| } | ||
|
|
||
| if _, err := fmt.Fprintf(output, | ||
| `<!DOCTYPE html> | ||
| <html> | ||
| <head><meta charset="utf-8"><style>html,body{margin:0;height:100%%}#viewer{width:100%%;height:100%%}#viewer>div{text-align:center;padding:1em}</style></head> | ||
| <body><div id="viewer"></div><script type="application/octet-stream" id="modelData" data-filename="%s">`, | ||
| html.EscapeString(path.Base(ctx.RenderOptions.RelativePath)), | ||
| ); err != nil { | ||
| return err | ||
| } | ||
|
|
||
| b64 := base64.NewEncoder(base64.StdEncoding, output) | ||
| if _, err := io.Copy(b64, io.LimitReader(input, setting.UI.MaxDisplayFileSize)); err != nil { | ||
| return err | ||
| } | ||
| if err := b64.Close(); err != nil { | ||
| return err | ||
| } | ||
|
|
||
| _, err := fmt.Fprintf(output, `</script><script type="module" src="%s"></script></body></html>`, public.AssetURI("js/viewer-3d.js")) | ||
| return err | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,13 @@ | ||
| import * as OV from 'online-3d-viewer'; | ||
|
|
||
| const modelDataScript = document.querySelector<HTMLElement>('#modelData')!; | ||
| const fileName = modelDataScript.getAttribute('data-filename')!; | ||
| const fileBytes = Uint8Array.from(atob(modelDataScript.textContent), (c) => c.charCodeAt(0)); | ||
|
|
||
| const container = document.querySelector<HTMLElement>('#viewer')!; | ||
| const viewer = new OV.EmbeddedViewer(container, { | ||
| backgroundColor: new OV.RGBAColor(59, 68, 76, 0), | ||
| defaultColor: new OV.RGBColor(65, 131, 196), | ||
| edgeSettings: new OV.EdgeSettings(false, new OV.RGBColor(0, 0, 0), 1), | ||
|
wxiaoguang marked this conversation as resolved.
Outdated
|
||
| }); | ||
| viewer.LoadModelFromFileList([new File([fileBytes], fileName)]); | ||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.