From 416b024ddd9ea74a6b14b87da917138743ad28b0 Mon Sep 17 00:00:00 2001 From: Jonny Gerig Meyer Date: Fri, 22 Sep 2023 11:22:43 -0400 Subject: [PATCH 1/5] Inefficient POC for unapplying polyfill. --- index.html | 110 ++++++++++++++++++++++++++++------- public/anchor-added.css | 14 +++++ src/constants.ts | 3 + src/fetch.ts | 21 +++---- src/index-fn.ts | 4 +- src/parse.ts | 14 +++-- src/polyfill.ts | 87 ++++++++++++++++++++++----- src/transform.ts | 58 +++++++++++------- tests/unit/fetch.test.ts | 5 +- tests/unit/parse.test.ts | 3 +- tests/unit/transform.test.ts | 13 +++-- 11 files changed, 253 insertions(+), 79 deletions(-) create mode 100644 public/anchor-added.css create mode 100644 src/constants.ts diff --git a/index.html b/index.html index d616e770..51fac1ac 100644 --- a/index.html +++ b/index.html @@ -33,6 +33,7 @@ + @@ -621,13 +623,25 @@

- Dynamically update anchors + Dynamically updated anchors

Anchor
Target
+

With polyfill applied: Target and Anchor's right edges line up. Target's top edge lines up with the bottom edge of the Anchor. @@ -645,6 +659,60 @@

position: absolute; right: anchor(--my-anchor-update right); top: anchor(--my-anchor-update bottom); +} +

+
+

+ + Dynamically added anchors +

+
+
Original Anchor
+
Target
+
+ + +

+ With polyfill applied: Target and original Anchor's right edges line up. + Target's top edge lines up with the top edge of the original Anchor. +
+
+ When another valid Anchor is added earlier in the DOM order and the + polyfill is re-applied, Target position updates relative to the added + Anchor. +

+
#my-anchor-added-new {
+  anchor-name: --my-anchor-added;
+  margin-bottom: 1rem;
+}
+
+#my-anchor-added-original {
+  anchor-name: --my-anchor-added;
+}
+
+#my-target-added {
+  position: absolute;
+  left: anchor(--my-anchor-added right);
+  top: anchor(--my-anchor-added top);
 }