Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
77 changes: 77 additions & 0 deletions examples/amp-story/performance/splitcss.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
<!-- Imports the story prestyle CSS so it can be laid out before the JS loads -->
<!doctype html>
<html ⚡ lang="en">
<head>
<meta charset="utf-8">
<link rel="canonical" href="lcp.html">
<meta name="viewport" content="width=device-width,minimum-scale=1,initial-scale=1">
<title>Boilerplate test</title>
<!-- <script async src="https://cdn.ampproject.org/v0.js"></script>
<script async custom-element="amp-story" src ="https://cdn.ampproject.org/v0/amp-story-1.0.js"></script> -->
<!-- Fonts -->
<link rel="preconnect" href="https://fonts.googleapis.com">
<link rel="preconnect" href="https://fonts.gstatic.com" crossorigin>
<link href="https://fonts.googleapis.com/css2?family=Poppins:wght@400;700&display=swap" rel="stylesheet">
<link rel="stylesheet" href="https://cdn.ampproject.org/v0/amp-story-1.0.css">

<style amp-boilerplate>body{-webkit-animation:-amp-start 8s steps(1,end) 0s 1 normal both;-moz-animation:-amp-start 8s steps(1,end) 0s 1 normal both;-ms-animation:-amp-start 8s steps(1,end) 0s 1 normal both;animation:-amp-start 8s steps(1,end) 0s 1 normal both}@-webkit-keyframes -amp-start{from{visibility:hidden}to{visibility:visible}}@-moz-keyframes -amp-start{from{visibility:hidden}to{visibility:visible}}@-ms-keyframes -amp-start{from{visibility:hidden}to{visibility:visible}}@-o-keyframes -amp-start{from{visibility:hidden}to{visibility:visible}}@keyframes -amp-start{from{visibility:hidden}to{visibility:visible}}</style><noscript><style amp-boilerplate>body{-webkit-animation:none;-moz-animation:none;-ms-animation:none;animation:none}</style></noscript>

<style amp-custom>
amp-story-page {
font-family: 'Poppins', sans-serif;
color: black;
background-color: white;
}
h1 {
color: black;
font-size: 2em;
}
h1.preset {
font-size: 0.5em;
}
[preset="2021-foreground"] {
align-content: end;
padding: .5em;
}
p {
font-size: 1em;
}
[preset="2021-foreground"] p {
font-size: 0.25em;
}
html {
background: red;
}
body {
background: blue;
}
</style>
</head>
<body>
<amp-story standalone id="cats"
title="LCP test" publisher="The AMP team"
publisher-logo-src="./img/amplogo.png"
poster-portrait-src="./img/overview.jpg">

<amp-story-page id="cover">
<amp-story-grid-layer template="fill">
<amp-img
id="img1"
width="400"
height="750"
src="https://images.unsplash.com/photo-1558591710-4b4a1ae0f04d?fit=crop&w=720&h=1280&q=30&fm=webp"
layout="fill">
</amp-img>
</amp-story-grid-layer>
<amp-story-grid-layer template="vertical">
<h1 class="hello-world">Story Prestyle + JS</h1>
<p>This is how a story looks with the prestyle+JS<br></p>
<p style="color: dimgray">Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.</p>
</amp-story-grid-layer>
<amp-story-grid-layer template="vertical" preset="2021-foreground">
<p style="color: dimgray">This text is positioned with an aspect-ratio layer</p>
</amp-story-grid-layer>
</amp-story-page>
</amp-story>
</body>
</html>
55 changes: 31 additions & 24 deletions extensions/amp-story/1.0/amp-story-desktop-one-panel.css
Original file line number Diff line number Diff line change
Expand Up @@ -2,38 +2,45 @@

@import './amp-story-desktop-user-overridable.css';

amp-story[standalone] {
background-color: black;
}

/**
* NOTE: If you change any variables or media queries change:
* css/amp-story-player-shadow.css
*/

/** Variables shared between page, system layer and pagination buttons. */
.i-amphtml-story-desktop-one-panel {
--i-amphtml-story-desktop-one-panel-ratio: 69 / 116;
--i-amphtml-story-desktop-one-panel-responsive-margin: max(74px, 8.25vh);
@media(min-aspect-ratio: 3/4) {
/** Variables shared between page, system layer and pagination buttons. */
:root:not([data-story-supports-landscape]) {
--i-amphtml-story-desktop-one-panel-ratio: 69 / 116;
--i-amphtml-story-desktop-one-panel-responsive-margin: max(74px, 8.25vh);
/** Calculates panel height by subtracting responsive vertical margin. */
--i-amphtml-story-desktop-one-panel-height: calc(100vh - var(--i-amphtml-story-desktop-one-panel-responsive-margin) * 2);
--i-amphtml-story-desktop-one-panel-width: calc(var(--i-amphtml-story-desktop-one-panel-height) * var(--i-amphtml-story-desktop-one-panel-ratio));
--i-amphtml-story-desktop-one-panel-border-radius: 10px;
}

@media(max-height: 756px) {
.i-amphtml-story-desktop-one-panel {
--i-amphtml-story-desktop-one-panel-responsive-margin: 0;
--i-amphtml-story-desktop-one-panel-width: calc(100vh * var(--i-amphtml-story-desktop-one-panel-ratio));
--i-amphtml-story-desktop-one-panel-border-radius: 0;
--i-amphtml-story-desktop-one-panel-height: calc(100vh - var(--i-amphtml-story-desktop-one-panel-responsive-margin) * 2);
--i-amphtml-story-desktop-one-panel-width: calc(var(--i-amphtml-story-desktop-one-panel-height) * var(--i-amphtml-story-desktop-one-panel-ratio));
--i-amphtml-story-desktop-one-panel-border-radius: 10px;
--story-page-vw: calc(var(--i-amphtml-story-desktop-one-panel-width) * .01) !important;
--story-page-vh: calc(var(--i-amphtml-story-desktop-one-panel-height) * .01) !important;
}
}

@media(max-height: 538px) {
.i-amphtml-story-desktop-one-panel {
--i-amphtml-story-desktop-one-panel-ratio: 3 / 4;
@media(max-height: 756px) {
:root:not([data-story-supports-landscape]) {
--i-amphtml-story-desktop-one-panel-responsive-margin: 0px;
--i-amphtml-story-desktop-one-panel-width: calc(100vh * var(--i-amphtml-story-desktop-one-panel-ratio));
--i-amphtml-story-desktop-one-panel-border-radius: 0;
}
}
}

.i-amphtml-story-desktop-one-panel amp-story-page {
width: var(--i-amphtml-story-desktop-one-panel-width) !important;
height: var(--i-amphtml-story-desktop-one-panel-height) !important;
border-radius: var(--i-amphtml-story-desktop-one-panel-border-radius) !important;
margin: auto !important;
@media(max-height: 538px) {
:root:not([data-story-supports-landscape]) {
--i-amphtml-story-desktop-one-panel-ratio: 3 / 4;
}
}
amp-story:not([supports-landscape]) amp-story-page {
width: var(--i-amphtml-story-desktop-one-panel-width) !important;
height: var(--i-amphtml-story-desktop-one-panel-height) !important;
border-radius: var(--i-amphtml-story-desktop-one-panel-border-radius) !important;
margin: auto !important;
}
}
26 changes: 2 additions & 24 deletions extensions/amp-story/1.0/amp-story-page.js
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ import {isPrerenderActivePage} from './prerender-active-page';
import {listen, listenOnce} from '../../../src/event-helper';
import {CSS as pageAttachmentCSS} from '../../../build/amp-story-open-page-attachment-0.1.css';
import {propagateAttributes} from '#core/dom/propagate-attributes';
import {px, toggle} from '#core/dom/style';
import {toggle} from '#core/dom/style';
import {renderPageAttachmentUI} from './amp-story-open-page-attachment';
import {renderPageDescription} from './semantic-render';
import {whenUpgradedToCustomElement} from '#core/dom/amp-element-helpers';
Expand Down Expand Up @@ -263,9 +263,6 @@ export class AmpStoryPage extends AMP.BaseElement {
/** @private @const {!./amp-story-store-service.AmpStoryStoreService} */
this.storeService_ = getStoreService(this.win);

/** @private {?Element} */
this.cssVariablesStyleEl_ = null;

/** @private {?../../../src/layout-rect.LayoutSizeDef} */
this.layoutBox_ = null;

Expand Down Expand Up @@ -625,32 +622,13 @@ export class AmpStoryPage extends AMP.BaseElement {
const {height, width} = layoutBox;
state.height = height;
state.width = width;
state.vh = height / 100;
state.vw = width / 100;
state.fiftyVw = Math.round(width / 2);
state.vmin = Math.min(state.vh, state.vw);
state.vmax = Math.max(state.vh, state.vw);
},
mutate: (state) => {
const {height, width} = state;
if (state.vh === 0 && state.vw === 0) {
if (state.height === 0 && state.width === 0) {
return;
}
this.storeService_.dispatch(Action.SET_PAGE_SIZE, {height, width});
if (!this.cssVariablesStyleEl_) {
const doc = this.win.document;
this.cssVariablesStyleEl_ = doc.createElement('style');
this.cssVariablesStyleEl_.setAttribute('type', 'text/css');
doc.head.appendChild(this.cssVariablesStyleEl_);
}
this.cssVariablesStyleEl_.textContent =
`:root {` +
`--story-page-vh: ${px(state.vh)};` +
`--story-page-vw: ${px(state.vw)};` +
`--story-page-vmin: ${px(state.vmin)};` +
`--story-page-vmax: ${px(state.vmax)};` +
`--i-amphtml-story-page-50vw: ${px(state.fiftyVw)};` +
`}`;
},
},
{}
Expand Down
6 changes: 4 additions & 2 deletions extensions/amp-story/1.0/amp-story-vertical.css
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@


/**
* Vertical scrolling rendering, so the pages are visible to search engine
* indexing tools, and not stacked on top of each other.
*/

html.i-amphtml-story-vertical {
--story-page-vh: 1.78vw !important;
}

amp-story[standalone][i-amphtml-vertical] {
height: auto !important;
contain: initial !important;
Expand Down
13 changes: 7 additions & 6 deletions extensions/amp-story/1.0/amp-story.css
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@


@import './amp-story-access.css';
@import './amp-story-affiliate-link.css';
@import './amp-story-desktop-one-panel.css';
Expand All @@ -12,6 +10,13 @@
@import './pagination-buttons.css';

/** Common */
:root {
--story-page-vw: 1vw !important;
--story-page-vh: 1vh !important;
--story-page-vmin: min(var(--story-page-vw), var(--story-page-vh)) !important;
--story-page-vmax: max(var(--story-page-vw), var(--story-page-vh)) !important;
font-size: calc(2.5 * var(--story-page-vh, 8px));
}
amp-story, amp-story-page, amp-story-cta-layer {
contain: strict !important;
overflow: hidden !important;
Expand Down Expand Up @@ -77,10 +82,6 @@ amp-story {
touch-action: manipulation !important;
}

html.i-amphtml-story-standalone {
font-size: calc(2.5 * var(--story-page-vmax, 8px));
}

html.i-amphtml-story-standalone,
html.i-amphtml-story-standalone body {
font-size: calc(2.5 * var(--story-page-vh, 8px));
Expand Down
9 changes: 9 additions & 0 deletions extensions/amp-story/1.0/amp-story.js
Original file line number Diff line number Diff line change
Expand Up @@ -366,6 +366,12 @@ export class AmpStory extends AMP.BaseElement {
this.initializeStoryPlayer_();

this.storeService_.dispatch(Action.TOGGLE_UI, this.getUIType_());
if (this.isLandscapeSupported_()) {
this.win.document.documentElement.setAttribute(
'data-story-supports-landscape',
''
);
}

// Removes title in order to prevent incorrect titles appearing on link
// hover. (See 17654)
Expand Down Expand Up @@ -1676,6 +1682,9 @@ export class AmpStory extends AMP.BaseElement {

this.vsync_.mutate(() => {
this.element.setAttribute('i-amphtml-vertical', '');
this.win.document.documentElement.classList.add(
'i-amphtml-story-vertical'
);
setImportantStyles(this.win.document.body, {height: 'auto'});
this.element.removeAttribute('desktop');
this.element.classList.remove('i-amphtml-story-desktop-fullbleed');
Expand Down