TASK: #103599 - edit container folder animation
This commit is contained in:
parent
4a46290727
commit
eab57a3d92
|
@ -10,3 +10,4 @@
|
||||||
- add blur
|
- add blur
|
||||||
- add contaienr
|
- add contaienr
|
||||||
- add SlotStyleHandler
|
- add SlotStyleHandler
|
||||||
|
- edit container folder animation
|
||||||
|
|
|
@ -5,6 +5,7 @@ import GestureManager from './gesture-manager'
|
||||||
import GaiaContainerPage from './gaia-container-page'
|
import GaiaContainerPage from './gaia-container-page'
|
||||||
import GaiaContainerFolder from './gaia-container-folder'
|
import GaiaContainerFolder from './gaia-container-folder'
|
||||||
import {DragAndDrop, STATUS, ChildElementInfo} from './contianer-interface'
|
import {DragAndDrop, STATUS, ChildElementInfo} from './contianer-interface'
|
||||||
|
import slotStyleHandler from '../../utils/SlotStyleHandler'
|
||||||
/**
|
/**
|
||||||
* 想法:
|
* 想法:
|
||||||
* 1. 用 grid 布局的特性排列应用图标(1×1)和小组件(n×m)
|
* 1. 用 grid 布局的特性排列应用图标(1×1)和小组件(n×m)
|
||||||
|
@ -188,14 +189,19 @@ class GaiaContainer extends LitElement {
|
||||||
super()
|
super()
|
||||||
this.row = row
|
this.row = row
|
||||||
this.column = column
|
this.column = column
|
||||||
|
;(window as any).con = this
|
||||||
// this.attachShadow({ mode: "open" });
|
// this.attachShadow({ mode: "open" });
|
||||||
|
|
||||||
// this.shadowRoot && (this.shadowRoot.innerHTML = this.template);
|
// this.shadowRoot && (this.shadowRoot.innerHTML = this.template);
|
||||||
}
|
}
|
||||||
|
|
||||||
firstUpdated() {
|
firstUpdated() {
|
||||||
|
slotStyleHandler.injectGlobalCss(
|
||||||
|
this,
|
||||||
|
GaiaContainer.styles.cssText,
|
||||||
|
this.name
|
||||||
|
)
|
||||||
let dndObserverCallback = () => {
|
let dndObserverCallback = () => {
|
||||||
console.log(this._dnd.enabled, this.dragAndDrop)
|
|
||||||
if (this._dnd.enabled !== this.dragAndDrop) {
|
if (this._dnd.enabled !== this.dragAndDrop) {
|
||||||
this._dnd.enabled = this.dragAndDrop
|
this._dnd.enabled = this.dragAndDrop
|
||||||
if (this._dnd.enabled) {
|
if (this._dnd.enabled) {
|
||||||
|
@ -517,6 +523,7 @@ class GaiaContainer extends LitElement {
|
||||||
* @returns 被添加的元素
|
* @returns 被添加的元素
|
||||||
*/
|
*/
|
||||||
realAppendChild(pagination = 0, ...args: HTMLElement[]) {
|
realAppendChild(pagination = 0, ...args: HTMLElement[]) {
|
||||||
|
if (pagination < 0) return
|
||||||
let page = this.pages[pagination]
|
let page = this.pages[pagination]
|
||||||
if (!page) {
|
if (!page) {
|
||||||
page = this.addPage()
|
page = this.addPage()
|
||||||
|
@ -1028,14 +1035,10 @@ class GaiaContainer extends LitElement {
|
||||||
for (let i = 0, iLen = children.length; i < iLen; i++) {
|
for (let i = 0, iLen = children.length; i < iLen; i++) {
|
||||||
let child = children[i] as GaiaContainerChild
|
let child = children[i] as GaiaContainerChild
|
||||||
if (
|
if (
|
||||||
childX >= (child._lastMasterLeft as number) &&
|
childX >= child._lastMasterLeft! &&
|
||||||
childY >= (child._lastMasterTop as number) &&
|
childY >= child._lastMasterTop! &&
|
||||||
childX <
|
childX < child._lastMasterLeft! + this.gridWidth * child.column &&
|
||||||
(child._lastMasterLeft as number) +
|
childY < child._lastMasterTop! + this.gridHeight * child.row
|
||||||
(child._lastElementWidth as number) &&
|
|
||||||
childY <
|
|
||||||
(child._lastMasterTop as number) +
|
|
||||||
(child._lastElementHeight as number)
|
|
||||||
) {
|
) {
|
||||||
if (child.pagination !== this._dnd.child.pagination) {
|
if (child.pagination !== this._dnd.child.pagination) {
|
||||||
// 当被选中元素与被移动元素页码不一致时,该次移动属于跨页移动
|
// 当被选中元素与被移动元素页码不一致时,该次移动属于跨页移动
|
||||||
|
@ -1120,11 +1123,14 @@ class GaiaContainer extends LitElement {
|
||||||
this._dnd.lastDropChild = null
|
this._dnd.lastDropChild = null
|
||||||
}
|
}
|
||||||
|
|
||||||
this._dnd.child?.container.style.setProperty(
|
this._dnd.child?.container?.style.setProperty(
|
||||||
'--offset-position-left',
|
'--offset-position-left',
|
||||||
'0px'
|
'0px'
|
||||||
)
|
)
|
||||||
this._dnd.child?.container.style.setProperty('--offset-position-top', '0px')
|
this._dnd.child?.container?.style.setProperty(
|
||||||
|
'--offset-position-top',
|
||||||
|
'0px'
|
||||||
|
)
|
||||||
this._dnd.child = null
|
this._dnd.child = null
|
||||||
this._dnd.isSpanning = false
|
this._dnd.isSpanning = false
|
||||||
this.status &= ~STATUS.DRAG
|
this.status &= ~STATUS.DRAG
|
||||||
|
@ -1351,6 +1357,7 @@ class GaiaContainer extends LitElement {
|
||||||
// 图标悬浮于另一个图标正上方
|
// 图标悬浮于另一个图标正上方
|
||||||
dropChild.master.classList.add('merging')
|
dropChild.master.classList.add('merging')
|
||||||
this.mergeTimer = setTimeout(() => {
|
this.mergeTimer = setTimeout(() => {
|
||||||
|
if (!this._dnd.child) return
|
||||||
this.mergeFolder(
|
this.mergeFolder(
|
||||||
(dropChild as GaiaContainerChild).master,
|
(dropChild as GaiaContainerChild).master,
|
||||||
this._dnd.child.master
|
this._dnd.child.master
|
||||||
|
@ -1364,10 +1371,10 @@ class GaiaContainer extends LitElement {
|
||||||
!dropChild.isWidget &&
|
!dropChild.isWidget &&
|
||||||
!this._dnd.child.isWidget
|
!this._dnd.child.isWidget
|
||||||
) {
|
) {
|
||||||
// 图标悬浮于文件夹正上方
|
|
||||||
this.clearMergeTimer()
|
this.clearMergeTimer()
|
||||||
dropChild.master.classList.add('merging')
|
dropChild.master.classList.add('merging')
|
||||||
this.mergeTimer = setTimeout(() => {
|
this.mergeTimer = setTimeout(() => {
|
||||||
|
if (!this._dnd.child) return
|
||||||
;(dropChild as GaiaContainerFolder).open()
|
;(dropChild as GaiaContainerFolder).open()
|
||||||
this.mergeFolder(
|
this.mergeFolder(
|
||||||
(dropChild as GaiaContainerFolder).master,
|
(dropChild as GaiaContainerFolder).master,
|
||||||
|
@ -1437,8 +1444,8 @@ class GaiaContainer extends LitElement {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
folder.addAppIcon(appMaster)
|
|
||||||
appendFolder(referenceNode as HTMLElement)
|
appendFolder(referenceNode as HTMLElement)
|
||||||
|
folder.addAppIcon(appMaster)
|
||||||
|
|
||||||
this._staticElements = this._staticElements.filter(
|
this._staticElements = this._staticElements.filter(
|
||||||
(el) => el !== folder.element
|
(el) => el !== folder.element
|
||||||
|
@ -1505,7 +1512,7 @@ class GaiaContainer extends LitElement {
|
||||||
)
|
)
|
||||||
} else if (this._dnd.timeout !== null && this._dnd.child?.isFolder) {
|
} else if (this._dnd.timeout !== null && this._dnd.child?.isFolder) {
|
||||||
this._dnd.child.open()
|
this._dnd.child.open()
|
||||||
} else if (this._dnd.timeout !== null) {
|
} else if (this._dnd.timeout !== null && this._dnd.child?.element) {
|
||||||
let handled = !this.dispatchEvent(
|
let handled = !this.dispatchEvent(
|
||||||
new CustomEvent('activate', {
|
new CustomEvent('activate', {
|
||||||
cancelable: true,
|
cancelable: true,
|
||||||
|
@ -1760,6 +1767,9 @@ class GaiaContainer extends LitElement {
|
||||||
child.synchroniseMaster()
|
child.synchroniseMaster()
|
||||||
// }
|
// }
|
||||||
}
|
}
|
||||||
|
if (Object.keys(this.folders).length) {
|
||||||
|
// debugger
|
||||||
|
}
|
||||||
|
|
||||||
for (let i = 0; i < children.length; i++) {
|
for (let i = 0; i < children.length; i++) {
|
||||||
child = children[i]
|
child = children[i]
|
||||||
|
@ -1840,6 +1850,10 @@ class GaiaContainer extends LitElement {
|
||||||
transform: opacity 0.1s;
|
transform: opacity 0.1s;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
::slotted(.gaia-container-child) {
|
||||||
|
width: 100%;
|
||||||
|
}
|
||||||
|
|
||||||
::slotted(.gaia-container-child.dragging) {
|
::slotted(.gaia-container-child.dragging) {
|
||||||
z-index: 1;
|
z-index: 1;
|
||||||
will-change: transform;
|
will-change: transform;
|
||||||
|
@ -1867,6 +1881,9 @@ class GaiaContainer extends LitElement {
|
||||||
}
|
}
|
||||||
`
|
`
|
||||||
|
|
||||||
|
editStyle(moduleName: string, style: string) {
|
||||||
|
this.shadowStyles[moduleName] = style
|
||||||
|
}
|
||||||
@state()
|
@state()
|
||||||
shadowStyles: {[subModule: string]: string} = new Proxy(
|
shadowStyles: {[subModule: string]: string} = new Proxy(
|
||||||
{},
|
{},
|
||||||
|
@ -1874,14 +1891,11 @@ class GaiaContainer extends LitElement {
|
||||||
set: (
|
set: (
|
||||||
target: {[module: string]: string},
|
target: {[module: string]: string},
|
||||||
prop: string,
|
prop: string,
|
||||||
value
|
value: string
|
||||||
): boolean => {
|
): boolean => {
|
||||||
console.log('prop', prop)
|
|
||||||
console.log('value', value)
|
|
||||||
console.log('target[prop]', target[prop])
|
|
||||||
|
|
||||||
if (!target[prop] || target[prop] !== value) {
|
if (!target[prop] || target[prop] !== value) {
|
||||||
target[prop] = value
|
target[prop] = value
|
||||||
|
slotStyleHandler.injectGlobalCss(this, value, this.name, prop)
|
||||||
this.requestUpdate()
|
this.requestUpdate()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -28,7 +28,6 @@ export default class GaiaContainerChild {
|
||||||
column: number
|
column: number
|
||||||
manager: GaiaContainer
|
manager: GaiaContainer
|
||||||
_isStatic: boolean | string
|
_isStatic: boolean | string
|
||||||
folderName: string = ''
|
|
||||||
anchorCoordinate: Coordinate
|
anchorCoordinate: Coordinate
|
||||||
// 静态位置
|
// 静态位置
|
||||||
_lastMasterTop: number | null = null
|
_lastMasterTop: number | null = null
|
||||||
|
@ -89,6 +88,11 @@ export default class GaiaContainerChild {
|
||||||
return inPage ? 'page' : 'folder'
|
return inPage ? 'page' : 'folder'
|
||||||
}
|
}
|
||||||
|
|
||||||
|
get folderName() {
|
||||||
|
const name = this.master.parentElement?.dataset.name
|
||||||
|
return name || ''
|
||||||
|
}
|
||||||
|
|
||||||
get element() {
|
get element() {
|
||||||
return this._element
|
return this._element
|
||||||
}
|
}
|
||||||
|
|
|
@ -34,10 +34,14 @@ export default class GaiaContainerFolder extends GaiaContainerChild {
|
||||||
}
|
}
|
||||||
|
|
||||||
init() {
|
init() {
|
||||||
this.addAnimationStyle()
|
this.manager.editStyle(
|
||||||
|
'GaiaContainerFolder',
|
||||||
|
GaiaContainerFolder.shadowStyle()
|
||||||
|
)
|
||||||
this.container.addEventListener('touchstart', this)
|
this.container.addEventListener('touchstart', this)
|
||||||
this.container.addEventListener('touchmove', this)
|
this.container.addEventListener('touchmove', this)
|
||||||
this.container.addEventListener('touchend', this)
|
this.container.addEventListener('touchend', this)
|
||||||
|
this.element.dataset.name = this.name
|
||||||
this.master.className = 'folder initializing'
|
this.master.className = 'folder initializing'
|
||||||
this.master.id = this._id
|
this.master.id = this._id
|
||||||
this.master.addEventListener(
|
this.master.addEventListener(
|
||||||
|
@ -53,7 +57,6 @@ export default class GaiaContainerFolder extends GaiaContainerChild {
|
||||||
)
|
)
|
||||||
this.container.appendChild(this.title)
|
this.container.appendChild(this.title)
|
||||||
this.container.style.width = this.manager.gridWidth + 'px'
|
this.container.style.width = this.manager.gridWidth + 'px'
|
||||||
// this.manager.injectGlobalCss(this.shadowStyle, this.manager.name, 'gaia-container-folder');
|
|
||||||
}
|
}
|
||||||
|
|
||||||
get element() {
|
get element() {
|
||||||
|
@ -109,16 +112,11 @@ export default class GaiaContainerFolder extends GaiaContainerChild {
|
||||||
}
|
}
|
||||||
|
|
||||||
showIconsSubtitle(element: HTMLElement) {
|
showIconsSubtitle(element: HTMLElement) {
|
||||||
const icon = element.querySelector(this.iconName)
|
element.removeAttribute(this.hideAttrName)
|
||||||
icon &&
|
|
||||||
icon.attributes.hasOwnProperty(this.hideAttrName) &&
|
|
||||||
icon.attributes.removeNamedItem(this.hideAttrName)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
hideIconsSubtitle(element: HTMLElement) {
|
hideIconsSubtitle(element: HTMLElement) {
|
||||||
const icon = element.querySelector(this.iconName)
|
element.setAttribute(this.hideAttrName, '')
|
||||||
const attr = document.createAttribute(this.hideAttrName)
|
|
||||||
icon && icon.attributes.setNamedItem(attr)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -156,9 +154,9 @@ export default class GaiaContainerFolder extends GaiaContainerChild {
|
||||||
|
|
||||||
this._children.push(child!)
|
this._children.push(child!)
|
||||||
if (!this._status) {
|
if (!this._status) {
|
||||||
this.hideIconsSubtitle(element)
|
this.hideIconsSubtitle(child?.element!)
|
||||||
} else {
|
} else {
|
||||||
this.showIconsSubtitle(element)
|
this.showIconsSubtitle(child?.element!)
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!this._status && shouldOpen) {
|
if (!this._status && shouldOpen) {
|
||||||
|
@ -168,7 +166,6 @@ export default class GaiaContainerFolder extends GaiaContainerChild {
|
||||||
this.movein(element)
|
this.movein(element)
|
||||||
this.element.appendChild(element)
|
this.element.appendChild(element)
|
||||||
}
|
}
|
||||||
child!.folderName = this.name
|
|
||||||
}
|
}
|
||||||
|
|
||||||
removeAppIcon(node: GaiaContainerChild | HTMLElement) {
|
removeAppIcon(node: GaiaContainerChild | HTMLElement) {
|
||||||
|
@ -183,8 +180,7 @@ export default class GaiaContainerFolder extends GaiaContainerChild {
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
if (!removeChild) return null
|
if (!removeChild) return null
|
||||||
;(removeChild as GaiaContainerChild).folderName = ''
|
this.showIconsSubtitle((removeChild as GaiaContainerChild).element!)
|
||||||
this.showIconsSubtitle((removeChild as GaiaContainerChild).container)
|
|
||||||
this.manager._children.push(removeChild as GaiaContainerChild)
|
this.manager._children.push(removeChild as GaiaContainerChild)
|
||||||
return removeChild
|
return removeChild
|
||||||
}
|
}
|
||||||
|
@ -213,10 +209,9 @@ export default class GaiaContainerFolder extends GaiaContainerChild {
|
||||||
*/
|
*/
|
||||||
open() {
|
open() {
|
||||||
if (this._status) return
|
if (this._status) return
|
||||||
const self = this
|
|
||||||
this._status = 1
|
this._status = 1
|
||||||
this.master.classList.add('openning')
|
this.master.classList.add('openning')
|
||||||
this._children.forEach((child) => this.showIconsSubtitle(child.master))
|
this._children.forEach((child) => this.showIconsSubtitle(child.element!))
|
||||||
this.manager.status |= 16
|
this.manager.status |= 16
|
||||||
this.manager.openedFolder = this
|
this.manager.openedFolder = this
|
||||||
this.container.style.height = '100%'
|
this.container.style.height = '100%'
|
||||||
|
@ -225,30 +220,35 @@ export default class GaiaContainerFolder extends GaiaContainerChild {
|
||||||
this.container.style.removeProperty('--grid-height')
|
this.container.style.removeProperty('--grid-height')
|
||||||
this.container.style.removeProperty('--grid-width')
|
this.container.style.removeProperty('--grid-width')
|
||||||
|
|
||||||
this.element.addEventListener('transitionend', function transitionend(evt) {
|
this.element.addEventListener('transitionend', this.openTransition)
|
||||||
if (evt.target == self.element && evt.propertyName == 'height') {
|
}
|
||||||
self._children.forEach((child) => child.synchroniseContainer())
|
|
||||||
|
openTransition = (evt: TransitionEvent) => {
|
||||||
|
if (evt.target == this.element && evt.propertyName == 'height') {
|
||||||
|
this._children.forEach((child) => child.synchroniseContainer())
|
||||||
|
}
|
||||||
|
|
||||||
|
if (
|
||||||
|
this._children[this._children.length - 1].master.compareDocumentPosition(
|
||||||
|
evt.target as HTMLElement
|
||||||
|
) & 16
|
||||||
|
) {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
this.container.style.setProperty('--folder-element-left', '0px')
|
||||||
|
this.container.style.setProperty('--folder-element-top', '0px')
|
||||||
|
this.openTimer = setTimeout(() => {
|
||||||
|
this.master.classList.remove('openning')
|
||||||
|
this.master.classList.add('opened')
|
||||||
|
let element = this.suspendElement.shift()
|
||||||
|
while (element) {
|
||||||
|
this.movein(element)
|
||||||
|
this.element.appendChild(element)
|
||||||
|
element = this.suspendElement.shift()
|
||||||
}
|
}
|
||||||
self.container.style.setProperty('--folder-element-left', '0px')
|
|
||||||
self.container.style.setProperty('--folder-element-top', '0px')
|
|
||||||
if (
|
|
||||||
self._children[self._children.length].master.compareDocumentPosition(
|
|
||||||
evt.target as HTMLElement
|
|
||||||
) & 16
|
|
||||||
)
|
|
||||||
return
|
|
||||||
self.openTimer = setTimeout(() => {
|
|
||||||
self.master.classList.remove('openning')
|
|
||||||
self.master.classList.add('opened')
|
|
||||||
let element = self.suspendElement.shift()
|
|
||||||
while (element) {
|
|
||||||
self.movein(element)
|
|
||||||
self.element.appendChild(element)
|
|
||||||
element = self.suspendElement.shift()
|
|
||||||
}
|
|
||||||
}, 200)
|
|
||||||
self.element.removeEventListener('transitionend', transitionend)
|
|
||||||
})
|
})
|
||||||
|
|
||||||
|
this.element.removeEventListener('transitionend', this.openTransition)
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -263,12 +263,16 @@ export default class GaiaContainerFolder extends GaiaContainerChild {
|
||||||
this.removeAppIcon(child)
|
this.removeAppIcon(child)
|
||||||
return false
|
return false
|
||||||
} else {
|
} else {
|
||||||
this.hideIconsSubtitle(child.master)
|
this.hideIconsSubtitle(child.element!)
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
this.master.classList.add('closing')
|
|
||||||
|
this.master.classList.remove('openning')
|
||||||
this.master.classList.remove('opened')
|
this.master.classList.remove('opened')
|
||||||
|
this.master.classList.add('closing')
|
||||||
|
this.element.removeEventListener('transitionend', this.openTransition)
|
||||||
|
|
||||||
this.manager.status &= ~16
|
this.manager.status &= ~16
|
||||||
this.manager.openedFolder = null
|
this.manager.openedFolder = null
|
||||||
this.container.style.height = this.manager.gridHeight + 'px'
|
this.container.style.height = this.manager.gridHeight + 'px'
|
||||||
|
@ -297,10 +301,9 @@ export default class GaiaContainerFolder extends GaiaContainerChild {
|
||||||
}
|
}
|
||||||
|
|
||||||
destroy() {
|
destroy() {
|
||||||
if (this._children.length > 1) {
|
if (this._children.length > 0) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
const {height: originHeight, width: originWidth} =
|
const {height: originHeight, width: originWidth} =
|
||||||
this.element.getBoundingClientRect()
|
this.element.getBoundingClientRect()
|
||||||
const {height: targetHeight, width: targetWidth} =
|
const {height: targetHeight, width: targetWidth} =
|
||||||
|
@ -308,6 +311,7 @@ export default class GaiaContainerFolder extends GaiaContainerChild {
|
||||||
|
|
||||||
const child = this._children[0]
|
const child = this._children[0]
|
||||||
const master = this._children[0].master
|
const master = this._children[0].master
|
||||||
|
this.manager._children.push(child)
|
||||||
const childContainer = master.querySelector(
|
const childContainer = master.querySelector(
|
||||||
'.gaia-container-child'
|
'.gaia-container-child'
|
||||||
) as HTMLElement
|
) as HTMLElement
|
||||||
|
@ -319,7 +323,7 @@ export default class GaiaContainerFolder extends GaiaContainerChild {
|
||||||
|
|
||||||
// nextTick,用以配合 originXXX 形成动画
|
// nextTick,用以配合 originXXX 形成动画
|
||||||
setTimeout(() => {
|
setTimeout(() => {
|
||||||
this.showIconsSubtitle(master)
|
this.showIconsSubtitle(this._children[0].element!)
|
||||||
this.element.style.height = targetHeight + 'px'
|
this.element.style.height = targetHeight + 'px'
|
||||||
this.element.style.width = targetWidth + 'px'
|
this.element.style.width = targetWidth + 'px'
|
||||||
})
|
})
|
||||||
|
@ -360,57 +364,23 @@ export default class GaiaContainerFolder extends GaiaContainerChild {
|
||||||
this._status &&
|
this._status &&
|
||||||
(evt.target as HTMLElement).tagName !== 'GAIA-APP-ICON'
|
(evt.target as HTMLElement).tagName !== 'GAIA-APP-ICON'
|
||||||
) {
|
) {
|
||||||
evt.preventDefault()
|
// evt.preventDefault()
|
||||||
evt.stopImmediatePropagation()
|
// evt.stopImmediatePropagation()
|
||||||
}
|
}
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
addAnimationStyle() {
|
static shadowStyle() {
|
||||||
const styleArr = document.head.querySelectorAll('style')
|
|
||||||
let styleNode
|
|
||||||
styleArr.forEach((item) => {
|
|
||||||
try {
|
|
||||||
if (item.dataset?.name === 'gaia') {
|
|
||||||
styleNode = item
|
|
||||||
}
|
|
||||||
} catch (error) {}
|
|
||||||
})
|
|
||||||
if (!styleNode) {
|
|
||||||
styleNode = document.createElement('style')
|
|
||||||
styleNode.dataset.name = 'gaia'
|
|
||||||
document.head.appendChild(styleNode)
|
|
||||||
}
|
|
||||||
styleNode.innerHTML += `
|
|
||||||
@keyframes folder-fadein {
|
|
||||||
0% {
|
|
||||||
opacity: 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
100% {
|
|
||||||
opacity: 1;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
`
|
|
||||||
}
|
|
||||||
|
|
||||||
get shadowStyle() {
|
|
||||||
return `
|
return `
|
||||||
::slotted(.gaia-container-child) {
|
::slotted(.gaia-container-child) {
|
||||||
box-sizing: content-box;
|
box-sizing: content-box;
|
||||||
}
|
}
|
||||||
::slotted(.gaia-container-folder) {
|
|
||||||
transition: transform 0.2s, box-shadow 0.2s, height 0.2s, width 0.2s !important;
|
|
||||||
}
|
|
||||||
::slotted(.folder:not(.opened)) .gaia-container-container {
|
|
||||||
}
|
|
||||||
::slotted(.gaia-container-folder) {
|
::slotted(.gaia-container-folder) {
|
||||||
display: grid;
|
display: grid;
|
||||||
position: unset;
|
position: unset;
|
||||||
grid-template-rows: repeat(3, 33.3%);
|
grid-template-rows: repeat(4, 25%);
|
||||||
grid-template-columns: repeat(3, 33.3%);
|
grid-template-columns: repeat(4, 25%);
|
||||||
grid-auto-flow: row dense;
|
grid-auto-flow: row dense;
|
||||||
height: 100%;
|
height: 100%;
|
||||||
width: 100%;
|
width: 100%;
|
||||||
|
@ -432,8 +402,8 @@ export default class GaiaContainerFolder extends GaiaContainerChild {
|
||||||
}
|
}
|
||||||
|
|
||||||
::slotted(.gaia-container-folder) .gaia-container-child {
|
::slotted(.gaia-container-folder) .gaia-container-child {
|
||||||
height: 16.5% !important;
|
height: 12.5% !important;
|
||||||
width: 16.5% !important;
|
width: 12.5% !important;
|
||||||
}
|
}
|
||||||
|
|
||||||
::slotted(.gaia-container-folder) gaia-app-icon {
|
::slotted(.gaia-container-folder) gaia-app-icon {
|
||||||
|
@ -465,6 +435,9 @@ export default class GaiaContainerFolder extends GaiaContainerChild {
|
||||||
transform: unset !important;
|
transform: unset !important;
|
||||||
transition: unset !important;
|
transition: unset !important;
|
||||||
}
|
}
|
||||||
|
::slotted(.folder.initializing) .container-master {
|
||||||
|
position: relative;
|
||||||
|
}
|
||||||
|
|
||||||
::slotted(.folder.initializing) {
|
::slotted(.folder.initializing) {
|
||||||
animation: folder-fadein 0.3s cubic-bezier(.08,.82,.17,1);
|
animation: folder-fadein 0.3s cubic-bezier(.08,.82,.17,1);
|
||||||
|
@ -497,7 +470,6 @@ export default class GaiaContainerFolder extends GaiaContainerChild {
|
||||||
|
|
||||||
::slotted(.folder-title) {
|
::slotted(.folder-title) {
|
||||||
font-size: 1rem;
|
font-size: 1rem;
|
||||||
color: #fff;
|
|
||||||
line-height: 1rem;
|
line-height: 1rem;
|
||||||
margin-top: 3px;
|
margin-top: 3px;
|
||||||
opacity: 1;
|
opacity: 1;
|
||||||
|
@ -521,6 +493,9 @@ export default class GaiaContainerFolder extends GaiaContainerChild {
|
||||||
::slotted(.folder.openning) > .gaia-container-child {
|
::slotted(.folder.openning) > .gaia-container-child {
|
||||||
transform: translate(0) !important;
|
transform: translate(0) !important;
|
||||||
}
|
}
|
||||||
|
::slotted(.folder.openning) .gaia-container-child {
|
||||||
|
transition: left 0.2s, height 0.2s, width 0.2s !important;
|
||||||
|
}
|
||||||
|
|
||||||
::slotted(.folder.openning) > .gaia-container-child,
|
::slotted(.folder.openning) > .gaia-container-child,
|
||||||
::slotted(.folder.closing) > .gaia-container-child {
|
::slotted(.folder.closing) > .gaia-container-child {
|
||||||
|
@ -548,6 +523,16 @@ export default class GaiaContainerFolder extends GaiaContainerChild {
|
||||||
::slotted(.folder.merging) .folder-title {
|
::slotted(.folder.merging) .folder-title {
|
||||||
opacity: 0;
|
opacity: 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@keyframes folder-fadein {
|
||||||
|
0% {
|
||||||
|
opacity: 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
100% {
|
||||||
|
opacity: 1;
|
||||||
|
}
|
||||||
|
}
|
||||||
`
|
`
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Binary file not shown.
After Width: | Height: | Size: 2.3 KiB |
|
@ -1,11 +1,15 @@
|
||||||
import {html, css, LitElement, TemplateResult} from 'lit'
|
import {html, css, LitElement, TemplateResult} from 'lit'
|
||||||
import {customElement, query, state} from 'lit/decorators.js'
|
import {customElement, query, state} from 'lit/decorators.js'
|
||||||
import GaiaContainer from '../../../components/grid-container/container'
|
import GaiaContainer from '../../../components/grid-container/container'
|
||||||
|
import GaiaContainerChild from '../../../components/grid-container/gaia-container-child'
|
||||||
|
import homescreenStyle from './homescreen-style'
|
||||||
|
|
||||||
import './icon'
|
import './icon'
|
||||||
|
|
||||||
@customElement('panel-container')
|
@customElement('panel-container')
|
||||||
export class PanelContainer extends LitElement {
|
export class PanelContainer extends LitElement {
|
||||||
container!: GaiaContainer
|
container!: GaiaContainer
|
||||||
|
icons: {[prop: string]: GaiaContainerChild} = {}
|
||||||
@query('.reset') resetBtn!: HTMLElement
|
@query('.reset') resetBtn!: HTMLElement
|
||||||
createRandomColor() {
|
createRandomColor() {
|
||||||
function randomInt(min: number, max: number) {
|
function randomInt(min: number, max: number) {
|
||||||
|
@ -23,35 +27,73 @@ export class PanelContainer extends LitElement {
|
||||||
}
|
}
|
||||||
addAppIcon() {
|
addAppIcon() {
|
||||||
;(window as any).panel = this
|
;(window as any).panel = this
|
||||||
console.log(this.container)
|
|
||||||
console.log('add')
|
|
||||||
const icon = document.createElement('site-icon')
|
const icon = document.createElement('site-icon')
|
||||||
|
|
||||||
icon.setAttribute('color', this.createRandomColor())
|
icon.setAttribute('color', this.createRandomColor())
|
||||||
this.container.appendContainerChild(icon)
|
this.container.appendContainerChild(icon)
|
||||||
|
this.icons[icon.name] = this.container.getChildByElement(icon)!
|
||||||
}
|
}
|
||||||
reset() {
|
reset() {}
|
||||||
console.log('reset')
|
|
||||||
}
|
|
||||||
firstUpdated() {
|
firstUpdated() {
|
||||||
this.container = new GaiaContainer()
|
this.container = new GaiaContainer()
|
||||||
this.container.setAttribute('dragAndDrop', 'true')
|
this.container.setAttribute('dragAndDrop', 'true')
|
||||||
this.shadowRoot?.appendChild(this.container)
|
this.shadowRoot?.appendChild(this.container)
|
||||||
;(window as any).container = this.container
|
;(window as any).container = this.container
|
||||||
|
;(window as any).home = this
|
||||||
|
this.addAppIcon()
|
||||||
}
|
}
|
||||||
|
@state() test!: string
|
||||||
|
@state()
|
||||||
|
protected styles: {[subModule: string]: string} = new Proxy(
|
||||||
|
{},
|
||||||
|
{
|
||||||
|
set: (
|
||||||
|
target: {[module: string]: string},
|
||||||
|
prop: string,
|
||||||
|
value
|
||||||
|
): boolean => {
|
||||||
|
if (!target[prop] || target[prop] !== value) {
|
||||||
|
target[prop] = value
|
||||||
|
this.requestUpdate()
|
||||||
|
}
|
||||||
|
|
||||||
|
return true
|
||||||
|
},
|
||||||
|
}
|
||||||
|
)
|
||||||
render() {
|
render() {
|
||||||
|
let style = ''
|
||||||
|
for (const subModule in this.styles) {
|
||||||
|
const str = this.styles[subModule]
|
||||||
|
style += str
|
||||||
|
style += '\n'
|
||||||
|
}
|
||||||
return html`
|
return html`
|
||||||
<button class="add" @click=${this.addAppIcon}>添加</button>
|
<style>
|
||||||
<button class="reset" @click=${this.reset}>重置</button>
|
${style}
|
||||||
|
</style>
|
||||||
|
<div class="btns">
|
||||||
|
<button class="add" @click=${this.addAppIcon}>添加</button>
|
||||||
|
<button class="reset" @click=${this.reset}>重置</button>
|
||||||
|
</div>
|
||||||
`
|
`
|
||||||
}
|
}
|
||||||
|
|
||||||
static styles = css`
|
static styles = [
|
||||||
star-container {
|
css`
|
||||||
height: 90vh;
|
star-container {
|
||||||
width: 100vw;
|
height: 90vh;
|
||||||
}
|
width: 100vw;
|
||||||
`
|
}
|
||||||
|
.btns {
|
||||||
|
position: fixed;
|
||||||
|
top: 0;
|
||||||
|
left: 0;
|
||||||
|
z-index: 1;
|
||||||
|
}
|
||||||
|
`,
|
||||||
|
homescreenStyle,
|
||||||
|
]
|
||||||
}
|
}
|
||||||
|
|
||||||
declare global {
|
declare global {
|
||||||
|
|
|
@ -0,0 +1,9 @@
|
||||||
|
import {css} from 'lit'
|
||||||
|
|
||||||
|
export default css`
|
||||||
|
/* 图标归位时的动画 */
|
||||||
|
star-container:not(.loading)
|
||||||
|
.gaia-container-child:not(.added):not(.dragging) {
|
||||||
|
transition: transform 0.2s;
|
||||||
|
}
|
||||||
|
`
|
|
@ -1,16 +1,19 @@
|
||||||
import {css} from 'lit'
|
import {css} from 'lit'
|
||||||
|
|
||||||
export default css`
|
export default css`
|
||||||
:host() {
|
:host([color]) {
|
||||||
position: absolute;
|
position: var(--width, absolute);
|
||||||
top: 50%;
|
top: 50%;
|
||||||
left: 50%;
|
left: 50%;
|
||||||
transform: translate(-50%, -50%);
|
width: 50%;
|
||||||
|
height: 50%;
|
||||||
|
max-width: var(--width);
|
||||||
|
max-height: var(--width);
|
||||||
|
border-radius: 50%;
|
||||||
}
|
}
|
||||||
#display {
|
#display {
|
||||||
--background-color: #fff;
|
--background-color: #fff;
|
||||||
width: 20vw;
|
width: 100%;
|
||||||
height: 12.5vh;
|
|
||||||
}
|
}
|
||||||
:host([hide-subtitle]) #subtitle {
|
:host([hide-subtitle]) #subtitle {
|
||||||
opacity: 0;
|
opacity: 0;
|
||||||
|
@ -23,12 +26,13 @@ export default css`
|
||||||
#image-container {
|
#image-container {
|
||||||
position: relative;
|
position: relative;
|
||||||
transition: visibility 0.2s, opacity 0.2s;
|
transition: visibility 0.2s, opacity 0.2s;
|
||||||
border: 50%;
|
border-radius: 50%;
|
||||||
background-color: var(--background-color);
|
background-color: var(--background-color);
|
||||||
}
|
}
|
||||||
|
|
||||||
#image-container img {
|
#image-container img {
|
||||||
display: block;
|
display: block;
|
||||||
|
opacity: 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
#image-container.initial-load {
|
#image-container.initial-load {
|
||||||
|
@ -51,10 +55,11 @@ export default css`
|
||||||
animation: rotate 2s infinite linear;
|
animation: rotate 2s infinite linear;
|
||||||
}
|
}
|
||||||
|
|
||||||
#image-container,
|
/* #image-container,
|
||||||
#image-container > div {
|
#image-container > div {
|
||||||
width: 100%;
|
width: 100%;
|
||||||
}
|
height: 100%;
|
||||||
|
} */
|
||||||
|
|
||||||
#subtitle {
|
#subtitle {
|
||||||
white-space: nowrap;
|
white-space: nowrap;
|
||||||
|
|
|
@ -3,15 +3,25 @@ import {customElement, property, query} from 'lit/decorators.js'
|
||||||
import style from './icon-style'
|
import style from './icon-style'
|
||||||
|
|
||||||
let count = 0
|
let count = 0
|
||||||
|
let imgBlob!: Blob
|
||||||
|
const getImage = (): Promise<Blob> => {
|
||||||
|
return new Promise((res, rej) => {
|
||||||
|
if (imgBlob) return res(imgBlob)
|
||||||
|
const canvas = document.createElement('canvas')
|
||||||
|
canvas.width = 100
|
||||||
|
canvas.height = 100
|
||||||
|
canvas.toBlob((blob) => (blob ? res(blob) : rej()))
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
@customElement('site-icon')
|
@customElement('site-icon')
|
||||||
export default class SiteIcon extends LitElement {
|
export default class SiteIcon extends LitElement {
|
||||||
static defaultColor = '#fff'
|
static defaultColor = '#fff'
|
||||||
_color = '#fff'
|
_color = '#fff'
|
||||||
|
name: string = `图标${++count}`
|
||||||
@query('#subtitle') subtitle!: HTMLElement
|
@query('#subtitle') subtitle!: HTMLElement
|
||||||
@query('#image-container') imgContainer!: HTMLElement
|
@query('#image-container') imgContainer!: HTMLElement
|
||||||
@query('#display') displayImg!: HTMLElement
|
@query('#display') displayImg!: HTMLImageElement
|
||||||
|
|
||||||
set color(value: string) {
|
set color(value: string) {
|
||||||
this._color = value
|
this._color = value
|
||||||
|
@ -31,17 +41,22 @@ export default class SiteIcon extends LitElement {
|
||||||
this.style.setProperty('--background-color', color)
|
this.style.setProperty('--background-color', color)
|
||||||
}
|
}
|
||||||
firstUpdated() {
|
firstUpdated() {
|
||||||
console.log('firstUpdated', this.displayImg)
|
const {width} = this.getBoundingClientRect()
|
||||||
|
this.style.setProperty('--width', width + 'px')
|
||||||
|
getImage().then((blob: Blob) => {
|
||||||
|
let url = URL.createObjectURL(blob)
|
||||||
|
this.displayImg.src = url
|
||||||
|
})
|
||||||
}
|
}
|
||||||
render() {
|
render() {
|
||||||
this.changeColor(this.color)
|
this.changeColor(this.color)
|
||||||
return html`
|
return html`
|
||||||
<div id="image-container">
|
<div id="image-container">
|
||||||
<div id="spinner"></div>
|
<div id="spinner"></div>
|
||||||
<img id="display" />
|
<img id="display" src="./asserts/icon.png" />
|
||||||
</div>
|
</div>
|
||||||
<div>
|
<div>
|
||||||
<div dir="auto" id="subtitle">图标${++count}</div>
|
<div dir="auto" id="subtitle">${this.name}</div>
|
||||||
</div>
|
</div>
|
||||||
`
|
`
|
||||||
}
|
}
|
||||||
|
|
|
@ -28,7 +28,6 @@ class SlotStyleHandler {
|
||||||
processCss(style: string, name: string) {
|
processCss(style: string, name: string) {
|
||||||
let globalCss = ''
|
let globalCss = ''
|
||||||
style.replace(this.regex.keyframes, (match) => {
|
style.replace(this.regex.keyframes, (match) => {
|
||||||
console.log('=====', match)
|
|
||||||
globalCss += match
|
globalCss += match
|
||||||
return ''
|
return ''
|
||||||
})
|
})
|
||||||
|
|
Loading…
Reference in New Issue