-
Notifications
You must be signed in to change notification settings - Fork 21
Size-reporter migrated to base vnext without sample changes #4014
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
Merged
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
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
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 |
|---|---|---|
| @@ -1,6 +1 @@ | ||
| ::ng-deep { | ||
| .custom-body { | ||
| color: var(--ig-surface-500-contrast); | ||
| background: var(--ig-surface-500); | ||
| } | ||
| } | ||
|
|
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 |
|---|---|---|
| @@ -1,6 +1 @@ | ||
| ::ng-deep { | ||
| .custom-body { | ||
| color: var(--ig-surface-500-contrast); | ||
| background: var(--ig-surface-500); | ||
| } | ||
| } | ||
|
|
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 |
|---|---|---|
| @@ -1,13 +1,4 @@ | ||
| .avatars-wrapper { | ||
| display: flex; | ||
| flex-flow: row wrap; | ||
| } | ||
|
|
||
| .avatar-sample { | ||
| display: flex; | ||
| flex: 1 0 30%; | ||
| width: 88px; | ||
| justify-content: center; | ||
| align-items: center; | ||
| margin: 15px 0; | ||
| :host { | ||
| display: inline-flex; | ||
| gap: 32px | ||
| } | ||
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,85 @@ | ||
| /** | ||
| * Demo-side half of the docs <Sample fitContent> contract | ||
| * (astro-components/src/scripts/sample-widget.ts). | ||
| * | ||
| * The docs host posts { type: 'igd-sample-fit', width?: boolean } into the | ||
| * iframe when it loads. In response we neutralize the viewport-bound sizing | ||
| * from styles.scss (html/body height: 100%, overflow: hidden — which would | ||
| * only echo the iframe's height back) and report the content's size with | ||
| * { type: 'igd-sample-height', height, width? } immediately and on every | ||
| * resize. Demos embedded at a fixed height never receive the enable message, | ||
| * so this stays dormant for them and their percentage layouts are untouched. | ||
| */ | ||
| const FIT_ENABLE = 'igd-sample-fit'; | ||
| const FIT_REPORT = 'igd-sample-height'; | ||
|
|
||
| export function initSampleSizeReporter(): void { | ||
| if (typeof window === 'undefined' || window.parent === window) { | ||
| return; | ||
| } | ||
|
|
||
| let reportWidth = false; | ||
| let observer: ResizeObserver | null = null; | ||
| let styled = false; | ||
| // Captured from the host's enable message so replies go back to that exact | ||
| // origin instead of being broadcast to any window that happens to listen. | ||
| let hostOrigin = '*'; | ||
|
|
||
| // Right-most element edge, mirroring the host's same-origin measurement: | ||
| // block-level content stretches to the viewport width, so the intrinsic | ||
| // width has to come from the element boxes, not the body itself. | ||
| const measureWidth = (): number | undefined => { | ||
| const body = document.body; | ||
| const left = body.getBoundingClientRect().left; | ||
| let right = left; | ||
| body.querySelectorAll('*').forEach(el => { | ||
| right = Math.max(right, el.getBoundingClientRect().right); | ||
| }); | ||
| if (right <= left) { | ||
| return undefined; | ||
| } | ||
| const cs = getComputedStyle(body); | ||
| return right - left + parseFloat(cs.paddingRight || '0') + parseFloat(cs.borderRightWidth || '0'); | ||
| }; | ||
|
ChronosSF marked this conversation as resolved.
|
||
|
|
||
| const report = () => { | ||
| const height = Math.max( | ||
| document.documentElement.offsetHeight, | ||
| document.body.offsetHeight, | ||
| document.body.scrollHeight | ||
| ); | ||
| window.parent.postMessage( | ||
| { type: FIT_REPORT, height, width: reportWidth ? measureWidth() : undefined }, | ||
| hostOrigin | ||
| ); | ||
| }; | ||
|
|
||
| window.addEventListener('message', (e: MessageEvent) => { | ||
| if (e.source !== window.parent) { | ||
| return; | ||
| } | ||
| if (!e.origin || !/^https?:\/\//.test(e.origin)) { | ||
| return; | ||
| } | ||
| if (!e.data || e.data.type !== FIT_ENABLE) { | ||
| return; | ||
| } | ||
| reportWidth = Boolean(e.data.width); | ||
| hostOrigin = e.origin; | ||
|
|
||
| if (!styled) { | ||
| styled = true; | ||
| const style = document.createElement('style'); | ||
| style.textContent = | ||
| 'html, body { height: auto !important; overflow: visible !important; }' + | ||
| '.sample-wrapper { height: auto !important; }'; | ||
| document.head.appendChild(style); | ||
| } | ||
|
|
||
| report(); | ||
| if ('ResizeObserver' in window && !observer) { | ||
| observer = new ResizeObserver(report); | ||
| observer.observe(document.body); | ||
| } | ||
| }); | ||
| } | ||
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
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.