forked from deckgo/deckdeckgo
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: peterpeterparker <[email protected]>
- Loading branch information
1 parent
653c0ef
commit 2983e84
Showing
13 changed files
with
338 additions
and
330 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,16 +1,16 @@ | ||
export function cleanContent(content: string): Promise<string> { | ||
return new Promise<string>(async (resolve) => { | ||
if (!content || content.length <= 0) { | ||
resolve(content); | ||
return; | ||
} | ||
return new Promise<string>(async (resolve) => { | ||
if (!content || content.length <= 0) { | ||
resolve(content); | ||
return; | ||
} | ||
|
||
let result: string = content.replace(/(<.*?)(contenteditable=""|contenteditable="true"|contenteditable="false"|contenteditable)(.*?>)/gi, '$1$3'); | ||
result = result.replace(/(<.*?)(editable=""|editable="true"|editable)(.*?>)/gi, '$1$3'); | ||
result = result.replace(/(<.*?)(highlighted=""|highlighted="true"|highlighted)(.*?>)/gi, '$1$3'); | ||
result = result.replace(/(<.*?)(custom-loader=""|custom-loader="true"|custom-loader)(.*?>)/gi, '$1$3'); | ||
result = result.replace(/class="[a-zA-Z0-9:;\.\s\(\)\-\,]*"/gi, ''); | ||
let result: string = content.replace(/(<.*?)(contenteditable=""|contenteditable="true"|contenteditable="false"|contenteditable)(.*?>)/gi, '$1$3'); | ||
result = result.replace(/(<.*?)(editable=""|editable="true"|editable)(.*?>)/gi, '$1$3'); | ||
result = result.replace(/(<.*?)(highlighted=""|highlighted="true"|highlighted)(.*?>)/gi, '$1$3'); | ||
result = result.replace(/(<.*?)(custom-loader=""|custom-loader="true"|custom-loader)(.*?>)/gi, '$1$3'); | ||
result = result.replace(/class="[a-zA-Z0-9:;\.\s\(\)\-\,]*"/gi, ''); | ||
|
||
resolve(result); | ||
}); | ||
resolve(result); | ||
}); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,27 +1,27 @@ | ||
export function convertStyle(originalStyle: string): Promise<any> { | ||
return new Promise<any>((resolve) => { | ||
if (!originalStyle || originalStyle.length <= 0) { | ||
resolve(undefined); | ||
return; | ||
} | ||
return new Promise<any>((resolve) => { | ||
if (!originalStyle || originalStyle.length <= 0) { | ||
resolve(undefined); | ||
return; | ||
} | ||
|
||
const result: any = {}; | ||
const result: any = {}; | ||
|
||
const styles: string[] = originalStyle.split(';'); | ||
const styles: string[] = originalStyle.split(';'); | ||
|
||
if (styles && styles.length > 0) { | ||
styles.forEach((style: string) => { | ||
if (style && style.length > 0) { | ||
const split: string[] = style.split(':'); | ||
if (split && split.length > 1) { | ||
result[split[0].trim()] = split[1].trim(); | ||
} else if (split && split.length > 0) { | ||
result[split[0].trim()] = undefined; | ||
} | ||
} | ||
}); | ||
if (styles && styles.length > 0) { | ||
styles.forEach((style: string) => { | ||
if (style && style.length > 0) { | ||
const split: string[] = style.split(':'); | ||
if (split && split.length > 1) { | ||
result[split[0].trim()] = split[1].trim(); | ||
} else if (split && split.length > 0) { | ||
result[split[0].trim()] = undefined; | ||
} | ||
} | ||
}); | ||
} | ||
|
||
resolve(result); | ||
}); | ||
resolve(result); | ||
}); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,85 +1,85 @@ | ||
import {DeckdeckgoSlideDefinition, DeckdeckgoAttributeDefinition} from '@deckdeckgo/types'; | ||
|
||
export function findSlidesTitle(): Promise<string[]> { | ||
return new Promise<string[]>((resolve) => { | ||
if (!document) { | ||
resolve(); | ||
return; | ||
} | ||
|
||
const results: string[] = []; | ||
|
||
const slides: NodeListOf<HTMLElement> = document.querySelectorAll('deckgo-deck > *'); | ||
|
||
if (slides) { | ||
for (const slide of Array.from(slides)) { | ||
if (slide.tagName && slide.tagName.toLowerCase().indexOf('deckgo-slide') > -1) { | ||
const title: HTMLElement | null = slide.querySelector('[slot="title"],[slot="question"]'); | ||
|
||
if (title && title.textContent && title.textContent !== '') { | ||
results.push(title.textContent); | ||
} else { | ||
const start: HTMLElement | null = slide.querySelector('[slot="start"],[slot="header"]'); | ||
|
||
if (start && start.textContent && start.textContent !== '') { | ||
results.push(start.textContent); | ||
} else { | ||
const end: HTMLElement | null = slide.querySelector('[slot="end"],[slot="footer"]'); | ||
|
||
if (end && end.textContent && end.textContent !== '') { | ||
results.push(end.textContent); | ||
} else { | ||
results.push(''); | ||
} | ||
} | ||
} | ||
} | ||
return new Promise<string[]>((resolve) => { | ||
if (!document) { | ||
resolve(); | ||
return; | ||
} | ||
|
||
const results: string[] = []; | ||
|
||
const slides: NodeListOf<HTMLElement> = document.querySelectorAll('deckgo-deck > *'); | ||
|
||
if (slides) { | ||
for (const slide of Array.from(slides)) { | ||
if (slide.tagName && slide.tagName.toLowerCase().indexOf('deckgo-slide') > -1) { | ||
const title: HTMLElement | null = slide.querySelector('[slot="title"],[slot="question"]'); | ||
|
||
if (title && title.textContent && title.textContent !== '') { | ||
results.push(title.textContent); | ||
} else { | ||
const start: HTMLElement | null = slide.querySelector('[slot="start"],[slot="header"]'); | ||
|
||
if (start && start.textContent && start.textContent !== '') { | ||
results.push(start.textContent); | ||
} else { | ||
const end: HTMLElement | null = slide.querySelector('[slot="end"],[slot="footer"]'); | ||
|
||
if (end && end.textContent && end.textContent !== '') { | ||
results.push(end.textContent); | ||
} else { | ||
results.push(''); | ||
} | ||
} | ||
} | ||
} | ||
} | ||
} | ||
|
||
resolve(results); | ||
}); | ||
resolve(results); | ||
}); | ||
} | ||
|
||
export function getSlideDefinition(slide: HTMLElement): Promise<DeckdeckgoSlideDefinition | null> { | ||
return new Promise<DeckdeckgoSlideDefinition | null>(async (resolve) => { | ||
if (!slide) { | ||
resolve(null); | ||
return; | ||
} | ||
|
||
const attributes: DeckdeckgoAttributeDefinition[] | null = await getAttributesDefinition(slide.attributes); | ||
|
||
resolve({ | ||
template: slide.tagName ? slide.tagName.toLowerCase() : undefined, | ||
content: slide.innerHTML, | ||
attributes: attributes | ||
}); | ||
return new Promise<DeckdeckgoSlideDefinition | null>(async (resolve) => { | ||
if (!slide) { | ||
resolve(null); | ||
return; | ||
} | ||
|
||
const attributes: DeckdeckgoAttributeDefinition[] | null = await getAttributesDefinition(slide.attributes); | ||
|
||
resolve({ | ||
template: slide.tagName ? slide.tagName.toLowerCase() : undefined, | ||
content: slide.innerHTML, | ||
attributes: attributes | ||
}); | ||
}); | ||
} | ||
|
||
export function getAttributesDefinition(attributes: NamedNodeMap): Promise<DeckdeckgoAttributeDefinition[] | null> { | ||
return new Promise<DeckdeckgoAttributeDefinition[] | null>(async (resolve) => { | ||
if (!attributes || attributes.length <= 0) { | ||
resolve(null); | ||
return; | ||
return new Promise<DeckdeckgoAttributeDefinition[] | null>(async (resolve) => { | ||
if (!attributes || attributes.length <= 0) { | ||
resolve(null); | ||
return; | ||
} | ||
|
||
const results: DeckdeckgoAttributeDefinition[] = []; | ||
Array.prototype.slice.call(attributes).forEach((attribute: Attr) => { | ||
if (['id', 'hydrated', 'class', 'contenteditable'].indexOf(attribute.name.toLowerCase()) === -1) { | ||
let attr: DeckdeckgoAttributeDefinition = { | ||
name: attribute.name | ||
}; | ||
|
||
if (attribute.value !== undefined) { | ||
attr.value = `${attribute.value}`; | ||
} | ||
|
||
const results: DeckdeckgoAttributeDefinition[] = []; | ||
Array.prototype.slice.call(attributes).forEach((attribute: Attr) => { | ||
if (['id', 'hydrated', 'class', 'contenteditable'].indexOf(attribute.name.toLowerCase()) === -1) { | ||
let attr: DeckdeckgoAttributeDefinition = { | ||
name: attribute.name | ||
}; | ||
|
||
if (attribute.value !== undefined) { | ||
attr.value = `${attribute.value}`; | ||
} | ||
|
||
results.push(attr); | ||
} | ||
}); | ||
|
||
resolve(results && results.length > 0 ? results : null); | ||
results.push(attr); | ||
} | ||
}); | ||
|
||
resolve(results && results.length > 0 ? results : null); | ||
}); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,3 @@ | ||
export interface DeckdeckgoComponent { | ||
lazyLoadContent(): Promise<void>; | ||
lazyLoadContent(): Promise<void>; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,9 @@ | ||
import {DeckdeckgoSlideResize} from './deckdeckgo-slide-resize'; | ||
|
||
export interface DeckdeckgoSlidePlay extends DeckdeckgoSlideResize { | ||
play(): Promise<void>; | ||
play(): Promise<void>; | ||
|
||
pause(): Promise<void>; | ||
pause(): Promise<void>; | ||
|
||
toggle(): Promise<void>; | ||
toggle(): Promise<void>; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
import {DeckdeckgoSlide} from './deckdeckgo-slide'; | ||
|
||
export interface DeckdeckgoSlideResize extends DeckdeckgoSlide { | ||
resizeContent(): Promise<void>; | ||
resizeContent(): Promise<void>; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,59 +1,59 @@ | ||
import {lazyLoadSelectedImages, lazyLoadSelectedLazyImagesComponent} from '@deckdeckgo/utils'; | ||
|
||
export function lazyLoadImages(el: HTMLElement): Promise<void> { | ||
return new Promise<void>(async (resolve) => { | ||
const promises = []; | ||
return new Promise<void>(async (resolve) => { | ||
const promises = []; | ||
|
||
promises.push(lazyLoadLazyImgTags(el)); | ||
promises.push(lazyLoadLazyImgComponents(el)); | ||
promises.push(lazyLoadLazyImgTags(el)); | ||
promises.push(lazyLoadLazyImgComponents(el)); | ||
|
||
await Promise.all(promises); | ||
await Promise.all(promises); | ||
|
||
resolve(); | ||
}); | ||
resolve(); | ||
}); | ||
} | ||
|
||
function lazyLoadLazyImgTags(el: HTMLElement): Promise<void> { | ||
return new Promise<void>(async (resolve) => { | ||
const images: HTMLElement[] = getAllImages(el, 'img'); | ||
return new Promise<void>(async (resolve) => { | ||
const images: HTMLElement[] = getAllImages(el, 'img'); | ||
|
||
await lazyLoadSelectedImages(images); | ||
await lazyLoadSelectedImages(images); | ||
|
||
resolve(); | ||
}); | ||
resolve(); | ||
}); | ||
} | ||
|
||
function lazyLoadLazyImgComponents(el: HTMLElement): Promise<void> { | ||
return new Promise<void>(async (resolve) => { | ||
const images: HTMLElement[] = getAllImages(el, 'deckgo-lazy-img'); | ||
return new Promise<void>(async (resolve) => { | ||
const images: HTMLElement[] = getAllImages(el, 'deckgo-lazy-img'); | ||
|
||
await lazyLoadSelectedLazyImagesComponent(images); | ||
await lazyLoadSelectedLazyImagesComponent(images); | ||
|
||
resolve(); | ||
}); | ||
resolve(); | ||
}); | ||
} | ||
|
||
export function hideLazyLoadImages(el: HTMLElement): Promise<void> { | ||
return new Promise<void>((resolve) => { | ||
let images: HTMLElement[] = getAllImages(el, 'img'); | ||
return new Promise<void>((resolve) => { | ||
let images: HTMLElement[] = getAllImages(el, 'img'); | ||
|
||
if (!images) { | ||
resolve(); | ||
} else { | ||
images = images.filter((image: HTMLElement) => image.getAttribute('data-src')); | ||
if (!images) { | ||
resolve(); | ||
} else { | ||
images = images.filter((image: HTMLElement) => image.getAttribute('data-src')); | ||
|
||
images.forEach((image: HTMLElement) => { | ||
image.style.setProperty('visibility', 'hidden'); | ||
}); | ||
images.forEach((image: HTMLElement) => { | ||
image.style.setProperty('visibility', 'hidden'); | ||
}); | ||
|
||
resolve(); | ||
} | ||
}); | ||
resolve(); | ||
} | ||
}); | ||
} | ||
|
||
function getAllImages(el: HTMLElement, tag: string): HTMLElement[] { | ||
const allSlotedImages: NodeListOf<HTMLElement> = el.querySelectorAll('[slot] ' + tag); | ||
const allShadowImages: NodeListOf<HTMLElement> | [] = el.shadowRoot ? el.shadowRoot.querySelectorAll(tag) : []; | ||
const allSlotedImages: NodeListOf<HTMLElement> = el.querySelectorAll('[slot] ' + tag); | ||
const allShadowImages: NodeListOf<HTMLElement> | [] = el.shadowRoot ? el.shadowRoot.querySelectorAll(tag) : []; | ||
|
||
return Array.from(allSlotedImages).concat(Array.from(allShadowImages)); | ||
return Array.from(allSlotedImages).concat(Array.from(allShadowImages)); | ||
} |
Oops, something went wrong.