<?xml version="1.0" encoding="utf-8" standalone="yes"?><rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:content="http://purl.org/rss/1.0/modules/content/"><channel><title>notes on Reorx’s Forge</title><link>https://reorx.com/tags/notes/</link><description>Recent content in notes on Reorx’s Forge</description><image><url>https://reorx.com/images/forge-v2-compat.svg</url><link>https://reorx.com/images/forge-v2-compat.svg</link></image><generator>Hugo -- gohugo.io</generator><lastBuildDate>Wed, 18 May 2022 00:00:00 +0800</lastBuildDate><atom:link href="https://reorx.com/tags/notes/feed.xml" rel="self" type="application/rss+xml"/><item><title>Google I/O 2022 Web Platform 新特性展示观看笔记</title><link>https://reorx.com/blog/notes-on-google-io-2022-web-platform-presentation/</link><pubDate>Wed, 18 May 2022 00:00:00 +0800</pubDate><guid>https://reorx.com/blog/notes-on-google-io-2022-web-platform-presentation/</guid><description>了解 Web 新技术从未如此充满乐趣。</description><content:encoded><![CDATA[<p>几天前临睡时看了 2022 Google IO 的一个 presentation: <a href="https://www.youtube.com/watch?v=5b4YcLB4DVI">What&rsquo;s new for the web platform</a>, 两位 Google 员工的解说让了解 Web 新技术的过程变得充满乐趣，于是做了些笔记在 <a href="https://threadreaderapp.com/thread/1525875286096904192.html">Twitter thread</a> 中。这篇文章对笔记进行了整理，并为每个特性附加详细说明的链接。</p>
<div class="tweet social-quote">
  <div class="title">
    <svg role="img" viewBox="0 0 24 24" fill="currentColor" xmlns="http://www.w3.org/2000/svg"><title>Twitter</title><path d="M23.953 4.57a10 10 0 01-2.825.775 4.958 4.958 0 002.163-2.723c-.951.555-2.005.959-3.127 1.184a4.92 4.92 0 00-8.384 4.482C7.69 8.095 4.067 6.13 1.64 3.162a4.822 4.822 0 00-.666 2.475c0 1.71.87 3.213 2.188 4.096a4.904 4.904 0 01-2.228-.616v.06a4.923 4.923 0 003.946 4.827 4.996 4.996 0 01-2.212.085 4.936 4.936 0 004.604 3.417 9.867 9.867 0 01-6.102 2.105c-.39 0-.779-.023-1.17-.067a13.995 13.995 0 007.557 2.209c9.053 0 13.998-7.496 13.998-13.985 0-.21 0-.42-.015-.63A9.935 9.935 0 0024 4.59z"/></svg>

    
  </div><blockquote class="twitter-tweet" data-dnt="true"><p lang="zh" dir="ltr">开个串记录下观看 Google IO What&#39;s new for the web platform 中发现的有趣的 feature<a href="https://t.co/LZPGGn7NHZ">https://t.co/LZPGGn7NHZ</a></p>&mdash; Reorx (@novoreorx) <a href="https://twitter.com/novoreorx/status/1525875286096904192?ref_src=twsrc%5Etfw">May 15, 2022</a></blockquote>


</div>


<h2 id="html">HTML</h2>
<h3 id="dialog"><code>&lt;dialog&gt;</code></h3>
<p><a href="https://web.dev/building-a-dialog-component/">https://web.dev/building-a-dialog-component/</a></p>
<p><code>&lt;dialog&gt;</code> 和 <code>&lt;selectmenu&gt;</code>，基本上所有 UI Kit 都会在组件库里实现的功能，终于被 HTML 原生实现了。如果 HTML 能多一些这种常用的交互组件，我会很乐意手写 Vanilla JS 来使用它们。</p>
<p><img loading="lazy" src="/blog/notes-on-google-io-2022-web-platform-presentation/images/google-io-2022-web-dialog.png" type="" alt=""  /></p>
<h3 id="selectmenu"><code>&lt;selectmenu&gt;</code></h3>
<p><a href="https://open-ui.org/prototypes/selectmenu">https://open-ui.org/prototypes/selectmenu</a></p>
<p><img loading="lazy" src="/blog/notes-on-google-io-2022-web-platform-presentation/images/google-io-2022-web-selectmenu.png" type="" alt=""  /></p>
<h3 id="input-typedatetile-local"><code>&lt;input type=datetile-local&gt;</code></h3>
<p><a href="https://developer.mozilla.org/en-US/docs/Web/HTML/Element/input/datetime-local">https://developer.mozilla.org/en-US/docs/Web/HTML/Element/input/datetime-local</a></p>
<p>记得 7 年前在豌豆荚工作时，因为这个标签不被 Firefox 支持，被迫找了一个 JavaScript 库来代替 (Pikaday, I still remember)。如今终于可以在主流浏览器上全面通用，太不容易了😭。</p>
<p><img loading="lazy" src="/blog/notes-on-google-io-2022-web-platform-presentation/images/google-io-2022-web-datetime-local.png" type="" alt=""  /></p>
<h2 id="css">CSS</h2>
<h3 id="has-selector"><code>:has</code> selector</h3>
<p><a href="https://developer.mozilla.org/en-US/docs/Web/CSS/:has">https://developer.mozilla.org/en-US/docs/Web/CSS/:has</a></p>
<p>用于声明父子元素关系的 :has 选择器！这个功能前阵子正好搜索过，现在只能用 JavaScript 实现。</p>
<p>图中的代码可以解释为，在包含 <code>&lt;figcaption&gt;</code> 的 <code>&lt;figure&gt;</code> 元素中，将其 children 中的 <code>&lt;img&gt;</code> 增加 1rem 的 bottom margin。</p>
<p><img loading="lazy" src="/blog/notes-on-google-io-2022-web-platform-presentation/images/google-io-2022-web-has.png" type="" alt=""  /></p>
<h3 id="aspect-ratio">Aspect ratio</h3>
<p><a href="https://web.dev/aspect-ratio/">https://web.dev/aspect-ratio/</a></p>
<p>CSS aspect-radio，使元素保持固定的宽高比。这是曾经在 <code>&lt;img&gt;</code> 标签上的实验特性，如今终于被所有元素支持了。</p>
<p><img loading="lazy" src="/blog/notes-on-google-io-2022-web-platform-presentation/images/google-io-2022-web-aspect-ratio.png" type="" alt=""  /></p>
<h3 id="cascade-layer">Cascade Layer</h3>
<p><a href="https://developer.chrome.com/blog/cascade-layers/">https://developer.chrome.com/blog/cascade-layers/</a></p>
<p>Cascade Layers, 给 CSS 加上了层级的概念，layer 可以自由排列顺序，后面的比前面的有更高的优先级 (specificity)；还展示了下越来越复杂的 CSS 优先级关系图，其实也可以把每一级都当做一个 layer。</p>
<p><img loading="lazy" src="/blog/notes-on-google-io-2022-web-platform-presentation/images/google-io-2022-web-cascade-layer.png" type="" alt=""  /></p>
<p><img loading="lazy" src="/blog/notes-on-google-io-2022-web-platform-presentation/images/google-io-2022-web-cascade-layer-1.png" type="" alt=""  /></p>
<h3 id="container-queries">Container queries</h3>
<p>Container queries，在响应式中能够发挥重要作用，但我基本没听懂，未来应该会影响一些 CSS 框架的 API，到时候再来学习吧。</p>
<p><img loading="lazy" src="/blog/notes-on-google-io-2022-web-platform-presentation/images/google-io-2022-web-container-queries.png" type="" alt=""  /></p>
<h3 id="accent-color">Accent color</h3>
<p><a href="https://web.dev/accent-color/">https://web.dev/accent-color/</a></p>
<p>CSS accent-color，为 HTML 基本元素设定一个统一的色调，主流浏览器在一年内都争先恐后地实现了😂，毕竟这是最能体现自己颜值的功能。不知道能不能和操作系统的 accent-color 互通，这样体验就更一致了。</p>
<p><img loading="lazy" src="/blog/notes-on-google-io-2022-web-platform-presentation/images/google-io-2022-web-accent-color.png" type="" alt=""  /></p>
<h2 id="javascript">JavaScript</h2>
<h3 id="arrayprototypeat">Array.prototype.at</h3>
<p><a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/at">https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/at</a></p>
<p>Array 增加了 at 方法，JavaScript 终于可以用类似 Python <code>list[-1]</code> 的写法了。这曾经是我刚学习 JavaScript 时觉得它不如 Python 最主要的原因。</p>
<p><img loading="lazy" src="/blog/notes-on-google-io-2022-web-platform-presentation/images/google-io-2022-web-array-at.png" type="" alt=""  /></p>
<h3 id="urlpattern">URLPattern</h3>
<p><a href="https://web.dev/urlpattern/">https://web.dev/urlpattern/</a></p>
<p>新类型 URLPattern，定义 URL 路径中的参数并解析出对应的 object。routing library 不用再写麻烦的正则了</p>
<p><img loading="lazy" src="/blog/notes-on-google-io-2022-web-platform-presentation/images/google-io-2022-web-urlpattern.png" type="" alt=""  /></p>
<h3 id="structuredclone">structuredClone</h3>
<p><a href="https://web.dev/structured-clone/">https://web.dev/structured-clone/</a></p>
<p>有了 structuredClone, 再也不用写 JSON.parse JSON.stringify 这种扭曲心智的代码了，非常适合在面试官问到 deep clone 的问题时反将一军。还可以用来 clone 其他数据结构如 blobs, bitmaps, typed arrays。</p>
<p><img loading="lazy" src="/blog/notes-on-google-io-2022-web-platform-presentation/images/google-io-2022-web-structuredclone.png" type="" alt=""  /></p>
<p><img loading="lazy" src="/blog/notes-on-google-io-2022-web-platform-presentation/images/google-io-2022-web-structuredclone-1.png" type="" alt=""  /></p>
<h3 id="createimagebitmap">createImageBitmap</h3>
<p><a href="https://developer.mozilla.org/en-US/docs/Web/API/createImageBitmap">https://developer.mozilla.org/en-US/docs/Web/API/createImageBitmap</a></p>
<p>createImageBitmap, 把 blob 直接转化成 Image 对象，改善了一直以来复杂而脆弱的写法。</p>
<p><img loading="lazy" src="/blog/notes-on-google-io-2022-web-platform-presentation/images/google-io-2022-web-blob.png" type="" alt=""  /></p>
<p><img loading="lazy" src="/blog/notes-on-google-io-2022-web-platform-presentation/images/google-io-2022-web-blob-1.png" type="" alt=""  /></p>
<h2 id="miscellaneous">Miscellaneous</h2>
<h3 id="chips">CHIPS</h3>
<p><a href="https://developer.chrome.com/docs/privacy-sandbox/chips/">https://developer.chrome.com/docs/privacy-sandbox/chips/</a></p>
<p>CHIPS 全称 Cookies Having Independent Partitioned State, 是 Cookie 在安全策略上的新特性，为 Set-Cookie 增加了 <code>Partitioned</code> 关键词。可以使特定 cookie 在 iframe 中只用于当前站点。自两年前 <code>SameSite</code> 关键词推广后，third-party cookie 只能选择全有或者全无，这次终于有了一个折中的选择。</p>
<p><img loading="lazy" src="/blog/notes-on-google-io-2022-web-platform-presentation/images/google-io-2022-web-chips.png" type="" alt=""  /></p>
<p><img loading="lazy" src="/blog/notes-on-google-io-2022-web-platform-presentation/images/google-io-2022-web-chips-1.png" type="" alt=""  /></p>
<h3 id="window-controls-overlay">Window controls overlay</h3>
<p><a href="https://web.dev/window-controls-overlay/">https://web.dev/window-controls-overlay/</a></p>
<p>Window controls overlay 是一组 <a href="https://developer.mozilla.org/en-US/docs/Web/Manifest">Web app manifests</a>, CSS, JavaScript API 的集合，实现了定制 PWA 窗口在 window bar 部分区域的显示效果，用于获得更有沉浸感的使用体验。</p>
<p><img loading="lazy" src="/blog/notes-on-google-io-2022-web-platform-presentation/images/google-io-2022-web-wco.png" type="" alt=""  /></p>
]]></content:encoded></item></channel></rss>