\(.*\))\s+(?.*)\s*/m'; /** * Smallest acceptable difference in floating point comparisons. * * @var float */ const FLOATING_POINT_EPSILON = 0.00001; /** * Associative array of custom sizer styles where the key is the ID of the associated element. * * @var string[] */ private $customSizerStyles = []; /** * Custom CSS rules that were extracted to remove blocking attributes. * * @var CssRules */ private $customCss; /** * Apply transformations to the provided DOM document. * * @param Document $document DOM document to apply the transformations to. * @param ErrorCollection $errors Collection of errors that are collected during transformation. * @return void */ public function transform(Document $document, ErrorCollection $errors) { if ($this->isAlreadyTransformed($document)) { return; } // Reset internal state for a new transform. $this->customCss = new CssRules(); /* * Within the loop we apply the layout to the custom tags (amp-foo...) where possible, but while we're at this * we also look for reasons not to remove the boilerplate. */ $canRemoveBoilerplate = true; foreach ($document->ampElements as $ampElement) { // Make sure we only deal with valid elements. if (! $ampElement instanceof Element) { continue; } // Skip tags inside a template tag. if ($this->isWithinTemplate($ampElement)) { continue; } /* * amp-experiment is a render delaying extension iff the tag is used in the doc. We check for that here * rather than checking for the existence of the amp-experiment script in IsRenderDelayingExtension below. */ if ($ampElement->tagName === Extension::EXPERIMENT && $this->isAmpExperimentUsed($ampElement)) { $errors->add(Error\CannotRemoveBoilerplate::fromAmpExperiment($ampElement)); $canRemoveBoilerplate = false; } /* * amp-audio requires knowing the dimensions of the browser. Do not remove the boilerplate or apply layout * if amp-audio is present in the document. */ if ($ampElement->tagName === Extension::AUDIO) { $errors->add(Error\CannotRemoveBoilerplate::fromAmpAudio($ampElement)); $canRemoveBoilerplate = false; } /* * Try to adapt 'sizes', 'heights' and 'media' attribute to turn them from blocking attributes into * CSS styles we add to