Skip to content

Commit

Permalink
[gem] Fixed Safari compatibility
Browse files Browse the repository at this point in the history
  • Loading branch information
mantou132 committed Dec 5, 2023
1 parent d015ccd commit 603914d
Show file tree
Hide file tree
Showing 26 changed files with 117 additions and 100 deletions.
2 changes: 1 addition & 1 deletion packages/duoyun-ui/src/elements/action-text.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ const style = createCSSSheet(css`
color: var(--color, inherit);
border-radius: ${theme.normalRound};
}
:host(:where(:hover, :--active, :state(active))) {
:host(:where(:hover, [data-active], :state(active))) {
color: var(--color, ${theme.primaryColor});
text-decoration: underline;
}
Expand Down
2 changes: 1 addition & 1 deletion packages/duoyun-ui/src/elements/base/chart.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ const style = createCSSSheet(css`
justify-content: center;
font-size: 0.75em;
}
:host(:where(:--loading, :state(loading), :--no-data, :state(nodata))) {
:host(:where([data-loading], :state(loading), [data-no-data], :state(no-data))) {
aspect-ratio: 2 / 1;
}
svg {
Expand Down
18 changes: 9 additions & 9 deletions packages/duoyun-ui/src/elements/base/scroll.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,32 +21,32 @@ const style = createCSSSheet(css`
--mask-start: var(--mask-top);
--mask-end: var(--mask-bottom);
}
:host(:where(:--top-overflow, :state(top-overflow))) {
:host(:where([data-top-overflow], :state(top-overflow))) {
--mask-top: var(--mask-width);
}
:host(:where(:--bottom-overflow, :state(bottom-overflow))) {
:host(:where([data-bottom-overflow], :state(bottom-overflow))) {
--mask-bottom: calc(100% - var(--mask-width));
}
:host(:where(:--left-overflow, :state(left-overflow), :--right-overflow, :state(right-overflow))) {
:host(:where([data-left-overflow], :state(left-overflow), [data-right-overflow], :state(right-overflow))) {
--mask-dir: right;
--mask-start: var(--mask-left);
--mask-end: var(--mask-right);
}
:host(:where(:--left-overflow, :state(left-overflow))) {
:host(:where([data-left-overflow], :state(left-overflow))) {
--mask-left: var(--mask-width);
}
:host(:where(:--right-overflow, :state(right-overflow))) {
:host(:where([data-right-overflow], :state(right-overflow))) {
--mask-right: calc(100% - var(--mask-width));
}
:host(
:where(
:--top-overflow,
[data-top-overflow],
:state(top-overflow),
:--bottom-overflow,
[data-bottom-overflow],
:state(bottom-overflow),
:--left-overflow,
[data-left-overflow],
:state(left-overflow),
:--right-overflow,
[data-right-overflow],
:state(right-overflow)
)
) {
Expand Down
4 changes: 2 additions & 2 deletions packages/duoyun-ui/src/elements/button.ts
Original file line number Diff line number Diff line change
Expand Up @@ -93,9 +93,9 @@ const style = createCSSSheet(css`
--bg: ${theme.disabledColor};
}
:where(
:host(:where(:--active, :state(active))) .content,
:host(:where([data-active], :state(active))) .content,
.content:where(:hover),
.dropdown:where(:hover, :--active, :state(active))
.dropdown:where(:hover, [data-active], :state(active))
)::after {
content: '';
position: absolute;
Expand Down
2 changes: 1 addition & 1 deletion packages/duoyun-ui/src/elements/card.ts
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ const style = createCSSSheet(css`
border-radius: ${theme.normalRound};
align-self: center;
}
.actions:where(:hover, :--active, :state(active)) {
.actions:where(:hover, [data-active], :state(active)) {
background-color: ${theme.hoverBackgroundColor};
}
slot[name='body']::slotted(*) {
Expand Down
2 changes: 1 addition & 1 deletion packages/duoyun-ui/src/elements/drop-area.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ const style = createCSSSheet(css`
display: none;
pointer-events: none;
}
:host(:where(:--allow-drop, :state(allow-drop))) .content {
:host(:where([data-allow-drop], :state(allow-drop))) .content {
display: block;
}
.tip {
Expand Down
4 changes: 2 additions & 2 deletions packages/duoyun-ui/src/elements/form.ts
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ const formStyle = createCSSSheet(css`
dy-form-item[type='checkbox'] {
flex-grow: 0;
}
dy-form-item:where(:--invalid, :state(invalid)) * {
dy-form-item:where([data-invalid], :state(invalid)) * {
border-color: ${theme.negativeColor};
}
dy-form-item-inline-group {
Expand Down Expand Up @@ -172,7 +172,7 @@ const formItemStyle = createCSSSheet(css`
.label:empty {
display: none;
}
:host(:where(:--invalid, :state(invalid))) .input {
:host(:where([data-invalid], :state(invalid))) .input {
border-color: ${theme.negativeColor};
}
.input {
Expand Down
2 changes: 1 addition & 1 deletion packages/duoyun-ui/src/elements/input.ts
Original file line number Diff line number Diff line change
Expand Up @@ -405,7 +405,7 @@ const inputGroupStyle = createCSSSheet(css`
dy-input-group {
display: flex;
}
dy-input-group :where(dy-input, dy-select):where(:focus, :focus-within, :hover, :--active, :state(active)) {
dy-input-group :where(dy-input, dy-select):where(:focus, :focus-within, :hover, [data-active], :state(active)) {
position: relative;
z-index: 1;
}
Expand Down
2 changes: 1 addition & 1 deletion packages/duoyun-ui/src/elements/modal.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ const style = createCSSSheet(css`
align-items: center;
justify-content: center;
}
:host(:not([hidden]):where([open], :where(:--closing, :state(closing)))) {
:host(:not([hidden]):where([open], :where([data-closing], :state(closing)))) {
display: flex;
}
.absolute {
Expand Down
2 changes: 1 addition & 1 deletion packages/duoyun-ui/src/elements/pagination.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ const style = createCSSSheet(css`
border: 1px solid transparent;
}
.item:where(:not(.disabled)):hover,
.item:where(:--active, :state(active)) {
.item:where([data-active], :state(active)) {
color: ${theme.highlightColor};
background-color: ${theme.hoverBackgroundColor};
}
Expand Down
4 changes: 2 additions & 2 deletions packages/duoyun-ui/src/elements/picker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ export const pickerStyle = createCSSSheet(css`
font-size: 0.875em;
box-sizing: border-box;
}
:host(:where(:--active, :state(active))) {
:host(:where([data-active], :state(active))) {
background: ${theme.lightBackgroundColor};
}
:host([disabled]) {
Expand All @@ -55,7 +55,7 @@ export const pickerStyle = createCSSSheet(css`
width: 1.2em;
color: ${theme.borderColor};
}
:host(:not([disabled]):where(:hover, :--active, :state(active))) dy-use {
:host(:not([disabled]):where(:hover, [data-active], :state(active))) dy-use {
color: ${theme.textColor};
}
`);
Expand Down
6 changes: 3 additions & 3 deletions packages/duoyun-ui/src/elements/select.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ const style = createCSSSheet(css`
:host {
width: 15em;
}
:host(:where(:hover, :--active, :state(active))) {
:host(:where(:hover, [data-active], :state(active))) {
background: none;
border-color: ${theme.textColor};
}
Expand Down Expand Up @@ -77,7 +77,7 @@ const style = createCSSSheet(css`
.search::part(input) {
padding: 0;
}
.search:where(:--filled, :state(filled), :--composing, :state(composing)) + .value {
.search:where([data-filled], :state(filled), [data-composing], :state(composing)) + .value {
display: none;
}
.value {
Expand Down Expand Up @@ -174,7 +174,7 @@ export class DuoyunSelectElement extends GemElement<State> implements BasePicker
super();
this.tabIndex = 0;
this.effect(() => {
this.internals.role = this.inline ? undefined : 'combobox';
this.internals.role = this.inline ? null : 'combobox';
this.internals.ariaExpanded = String(this.state.open);
this.internals.ariaReadOnly = String(this.disabled);
});
Expand Down
2 changes: 1 addition & 1 deletion packages/duoyun-ui/src/elements/side-navigation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ const style = createCSSSheet(css`
.children .item {
padding-inline-start: calc(0.75em + 1em);
}
.item:where(:hover, :--active, :state(active)) {
.item:where(:hover, [data-active], :state(active)) {
background-color: ${theme.hoverBackgroundColor};
}
.group {
Expand Down
4 changes: 2 additions & 2 deletions packages/duoyun-ui/src/elements/table.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ const style = createCSSSheet(css`
table-layout: fixed;
border-collapse: collapse;
}
.selection:where(:--selecting, :state(selecting)) ~ table {
.selection:where([data-selecting], :state(selecting)) ~ table {
user-select: none;
}
.selection ~ table {
Expand Down Expand Up @@ -100,7 +100,7 @@ const style = createCSSSheet(css`
padding: 4px;
border-radius: ${theme.normalRound};
}
.action:where(:hover, :--active, :state(active)) {
.action:where(:hover, [data-active], :state(active)) {
background-color: ${theme.hoverBackgroundColor};
}
.side {
Expand Down
2 changes: 1 addition & 1 deletion packages/duoyun-ui/src/elements/tabs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,7 @@ const panelStyle = createCSSSheet(css`
line-height: 1.5;
margin-block-start: 1em;
}
:host(:where(:--vertical, :state(vertical))) {
:host(:where([data-vertical], :state(vertical))) {
margin-inline-start: 1em;
margin-block-start: 0em;
}
Expand Down
2 changes: 1 addition & 1 deletion packages/duoyun-ui/src/elements/wait.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ const style = createCSSSheet(css`
dy-loading {
padding: 1em;
}
:host(:where(:--modal, :state(modal))) {
:host(:where([data-modal], :state(modal))) {
pointer-events: all;
background-color: rgba(0, 0, 0, ${theme.maskAlpha});
}
Expand Down
4 changes: 2 additions & 2 deletions packages/gem-book/src/element/elements/nav.ts
Original file line number Diff line number Diff line change
Expand Up @@ -130,10 +130,10 @@ export class Nav extends GemElement {
background: rgba(${theme.primaryColorRGB}, 0.1);
}
gem-active-link:hover,
gem-active-link:where(:state(active), :--active) {
gem-active-link:where(:state(active), [data-active]) {
color: ${theme.primaryColor};
}
gem-active-link:where(:state(active), :--active)::after {
gem-active-link:where(:state(active), [data-active])::after {
content: '';
position: absolute;
left: 0;
Expand Down
27 changes: 13 additions & 14 deletions packages/gem-book/src/element/elements/pre.ts
Original file line number Diff line number Diff line change
Expand Up @@ -489,22 +489,21 @@ export class Pre extends GemElement {
}

render() {
// Safari 精度问题
const lineHeight = 1.7;
const padding = 1;
// Safari 精度问题所以使用整数像素单位
const lineHeight = '24px';
const padding = '1em';
return html`
${this.highlight
? this.#getRanges(this.highlight).map(
([start, end]) =>
html`
<span
class="gem-highlight"
style=${styleMap({
top: `${(start - 1) * lineHeight + padding}em`,
height: `${(end - start + 1) * lineHeight}em`,
})}
></span>
`,
([start, end]) => html`
<span
class="gem-highlight"
style=${styleMap({
top: `calc(${start - 1} * ${lineHeight} + ${padding})`,
height: `calc(${end - start + 1} * ${lineHeight})`,
})}
></span>
`,
)
: ''}
<code
Expand All @@ -518,7 +517,7 @@ export class Pre extends GemElement {
>
<style>
code {
padding: ${padding}em;
padding: ${padding};
line-height: ${lineHeight};
}
</style>
Expand Down
10 changes: 5 additions & 5 deletions packages/gem-book/src/element/elements/sidebar.ts
Original file line number Diff line number Diff line change
Expand Up @@ -95,14 +95,14 @@ export class SideBar extends GemElement {
padding: 0.15em 0;
color: inherit;
}
.file:where(:state(active), :--active) {
.file:where(:state(active), [data-active]) {
font-weight: bolder;
}
.link:where(:state(active), :--active) + .hash {
.link:where(:state(active), [data-active]) + .hash {
display: block;
}
.heading:not(:where(:state(active), :--active)):not(:hover),
.file:not(:where(:state(active), :--active)):hover {
.heading:not(:where(:state(active), [data-active])):not(:hover),
.file:not(:where(:state(active), [data-active])):hover {
opacity: 0.6;
}
.arrow {
Expand Down Expand Up @@ -166,7 +166,7 @@ export class SideBar extends GemElement {
}

updated() {
const activeEle = this.shadowRoot?.querySelector(':where(:state(active), :--active)');
const activeEle = this.shadowRoot?.querySelector(':where(:state(active), [data-active])');
const removeCloseClass = (e: Element | null | undefined) => {
if (e) {
e.classList.remove('close');
Expand Down
2 changes: 1 addition & 1 deletion packages/gem-examples/src/decorator/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ export class App extends GemElement {
console.log('parent render');
return html`
<style>
app-children:where(:--odd, :state(odd))::part(${Children.paragraph}) {
app-children:where([data-odd], :state(odd))::part(${Children.paragraph}) {
color: red;
}
</style>
Expand Down
2 changes: 1 addition & 1 deletion packages/gem-examples/src/dialog/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ class Dialog extends GemDialogBaseElement {
:host {
display: none;
}
:host(:where(:--opened, :state(opened))) {
:host(:where([data-opened], :state(opened))) {
display: block;
}
.root {
Expand Down
4 changes: 2 additions & 2 deletions packages/gem-examples/src/ref-route/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ export class RouteHome extends GemElement {
gem-active-link {
display: block;
}
gem-active-link:where(:--active, :state(active)) {
gem-active-link:where([data-active], :state(active)) {
color: inherit;
}
</style>
Expand All @@ -58,7 +58,7 @@ export class RouteA extends GemElement {
gem-active-link {
display: block;
}
gem-active-link:where(:--active, :state(active)) {
gem-active-link:where([data-active], :state(active)) {
color: inherit;
}
</style>
Expand Down
Loading

0 comments on commit 603914d

Please sign in to comment.