当前位置: 首页 > 软件库 > 程序开发 > >

ember-shadow-dom

授权协议 MIT License
开发语言 JavaScript
所属分类 程序开发
软件类型 开源软件
地区 不详
投 递 者 酆晔
操作系统 跨平台
开源组织
适用人群 未知
 软件概览

ember-shadow-dom

Write templates for your components inside of a Shadow DOM root.Allows encapsulating styles (CSS) and markup (HTML) but using templates likeyou're used to.

�� Support for SSR/FastBoot in Chrome 90+, Release notes.

�� Not sure what Shadow DOM is? Check out this MDN article.

Compatibility: Most browsers support Shadow DOM (v1), except for IE11, see CanIUse for details

Compatibility

  • Ember.js v3.16 or above
  • Ember CLI v2.13 or above
  • Node.js v12 or above

If using Ember < 3.20, this addon will use the private version of {{in-element}} via a polyfill.

Installation

ember install ember-shadow-dom

Usage

This addon provides a component called ShadowRoot.

<ShadowRoot>
  <style>
    .internal { color: red; }
  </style>

  <span class='internal'>Internal</span>
</ShadowRoot>

This makes the encapsulating component's children a shadow root.

Slots

In Shadow DOM you can generally use <slots>, but with Ember you can just use {{yield}}.

{{! components/test.hbs }}
<ShadowRoot>
  <style>
    .internal { color: red; }
  </style>

  <span class='internal'>
    {{yield}}
  </span>
</ShadowRoot>

And you can call the component:

<Test>
  Hello World!
</Test>

And the contents Hello World! will be inside the shadow root. If you need multiple"slots", you can use ember-named-blocks-polyfill.

{{! components/card.hbs }}
<ShadowRoot ...attributes>
  <style>
    .title { color: red; } .body { margin-top: 1rem; }
  </style>

  <header class='title'>
    {{yield to='title'}}
  </header>

  <div class='body'>
    {{yield to='body'}}
  </div>
</ShadowRoot>

And use the component like so:

<Card class='custom-card'>
  <:title>
    My title
  </:title>

  <:body>
    Some content here!
  </:body>
</Card>

API

<ShadowRoot> Component

Arguments

  • @mode (string) - The mode of the Shadow Root, defaults to 'open'. Can be 'open' or 'closed'.Note that 'closed' mode prevents you from querying into the DOM of your components in tests.
  • @tagName (string) - This defaults to 'div', but can be any valid element tag name used in HTML.Setting this argument changes the top level element that the shadow root is attached to.

FastBoot/SSR

This addon supports ShadowDom in SSR (meaning your styles will remain the same on initial render and not change when rehydrated) in Chrome 90+

Other browser vendors should follow, but there is some risk that it never happens.Details here: https://www.chromestatus.com/feature/5191745052606464

Testing

Components with a open shadowroot can be tested using qunit-dom like so:

let root = find('#internal').shadowRoot;
assert.dom('.block', root).hasText('template block text');

Where the template looks like:

<ShadowRoot id='internal'>
  <div class='block'>template block text</div>
</ShadowRoot>

Contributing

See the Contributing guide for details.

Attribution

Thanks to @rwjblue for realizing that {{in-element}} can be used for the shadow root!

License

This project is licensed under the MIT License.

 相关资料
  • 此效果会创建具有模糊边缘的指定节点的副本。 包javafx.scene.effect名为Shadow的类表示棕褐色调效果。 该类包含六个属性,它们是 - color - 此属性为Color类型,表示阴影的颜色。 blur type - 此属性属于BlurType,它表示用于模糊阴影的模糊效果的类型。 radius - 此属性的类型为double,它表示阴影模糊内核的半径。 width - 此属性的

  • Shadow是一个腾讯自主研发的Android插件框架,经过线上亿级用户量检验。 Shadow不仅开源分享了插件技术的关键代码,还完整的分享了上线部署所需要的所有设计。 与市面上其他插件框架相比,Shadow主要具有以下特点: 复用独立安装App的源码:插件App的源码原本就是可以正常安装运行的。 零反射无Hack实现插件技术:从理论上就已经确定无需对任何系统做兼容开发,更无任何隐藏API调用,和

  • 描述 (Description) text-shadow属性指定一个或多个从元素文本派生的阴影。 可能的值 (Possible Values) none - 不应将阴影与元素相关联。 color - 任何颜色值。 这给出了阴影的颜色。 length length length - 阴影的偏移距离和模糊半径,按x偏移,y偏移和模糊半径的顺序。 适用于 (Applies to) 所有HTML元素。 D

  • CSS3支持向文本或elements添加阴影。阴影属性分为以下几种 - 文字阴影 盒子阴影 文字阴影 支持CSS3为文本添加阴影效果。 以下是向文本添加阴影效果的示例 - <html> <head> <style> h1 { text-shadow: 2px 2px; } h2 {

  • 简介 The box-shadow CSS property is used to add shadow effects around an element's frame. You can specify multiple effects separated by commas if you wish to do so. A box shadow is described by X and Y

  • 这个插件可以创建非常真实的阴影效果。非常适合做 demo 或者首页。 示例代码: $(selector).realshadow(); // options are optional$(selector).realshadow({ followMouse: false, // true by default pageX: x, // x coordinate