Commit 9db9b45e by ramdayalmunda

header changes

parent 01295e1a
...@@ -119,20 +119,22 @@ canvas:focus-visible { ...@@ -119,20 +119,22 @@ canvas:focus-visible {
overflow-x: auto; overflow-x: auto;
overflow-y: hidden; overflow-y: hidden;
} }
.content-area .left-sidebar{
.content-area .left-sidebar {
width: 200px; width: 200px;
background-color:#408640; background-color: #408640;
padding: 5px; padding: 5px;
} }
.content-area .right-sidebar{ .content-area .right-sidebar {
width: 200px; width: 200px;
background-color: #f5c468; background-color: #f5c468;
padding: 5px; padding: 5px;
} }
.content-area .left-sidebar, .content-area .left-sidebar,
.content-area .page-list, .content-area .page-list,
.content-area .right-sidebar{ .content-area .right-sidebar {
flex-shrink: 0; flex-shrink: 0;
height: 100%; height: 100%;
overflow-x: hidden; overflow-x: hidden;
...@@ -143,15 +145,16 @@ canvas:focus-visible { ...@@ -143,15 +145,16 @@ canvas:focus-visible {
} }
.left-sidebar .toggle-btn, .left-sidebar .toggle-btn,
.right-sidebar .toggle-btn{ .right-sidebar .toggle-btn {
display: block; display: block;
position: static; position: static;
top: 0; top: 0;
width: 100%; width: 100%;
text-align: center; text-align: center;
} }
.left-sidebar .content, .left-sidebar .content,
.right-sidebar .content{ .right-sidebar .content {
opacity: 1; opacity: 1;
position: relative; position: relative;
left: 0%; left: 0%;
...@@ -159,14 +162,15 @@ canvas:focus-visible { ...@@ -159,14 +162,15 @@ canvas:focus-visible {
} }
.left-sidebar.hide, .left-sidebar.hide,
.right-sidebar.hide{ .right-sidebar.hide {
width: 50px; width: 50px;
} }
.left-sidebar.hide .content, .left-sidebar.hide .content,
.right-sidebar.hide .content{ .right-sidebar.hide .content {
opacity: 0; opacity: 0;
} }
.page-list { .page-list {
position: relative; position: relative;
display: block; display: block;
...@@ -185,6 +189,7 @@ canvas:focus-visible { ...@@ -185,6 +189,7 @@ canvas:focus-visible {
position: relative; position: relative;
margin-top: 20px; margin-top: 20px;
margin-bottom: 20px; margin-bottom: 20px;
margin-right: 2px;
} }
.footer { .footer {
...@@ -198,10 +203,26 @@ canvas:focus-visible { ...@@ -198,10 +203,26 @@ canvas:focus-visible {
0% { 0% {
background: #fff; background: #fff;
} }
50% { 50% {
background: #ddd; background: #ddd;
} }
100% { 100% {
background: #fff; background: #fff;
} }
} }
*::-webkit-scrollbar {
background: transparent;
}
*::-webkit-scrollbar-track {
background-color: #00000022;
border-radius: 5px;
}
*::-webkit-scrollbar-thumb {
background: #7dbbb3;
border-radius: 5px;
}
\ No newline at end of file
let isModule = (typeof module != 'undefined') ? true : false let isModule = (typeof module != 'undefined') ? true : false
if (!isModule) console.log('Browser Environment') if (!isModule) console.log('Browser Environment')
var ADocEditor = function (customConfig) { var ADocEditor = function (customConfig) {
var container, counter = 0, shadow, pxMmRatio, config, htmlStr, htmlTag, htmlObj = {}, fontList = [], headerToolbar = []; var container, counter = 0, shadow, pxMmRatio, config, htmlStr, htmlTag, htmlObj = {}, fontList = [];
const mmPtRatio = 254 / 720; // this is used for font size const mmPtRatio = 254 / 720; // this is used for font size
var paperSizes = { var paperSizes = {
"A4": { mmWidth: 210, mmHeight: 297 }, "A4": { mmWidth: 210, mmHeight: 297 },
...@@ -10,11 +10,15 @@ var ADocEditor = function (customConfig) { ...@@ -10,11 +10,15 @@ var ADocEditor = function (customConfig) {
const romanNumerals = [["I", "IV", "V", "IX"], ["X", "XL", "L", "XC"], ["C", "CD", "D", "CM"], ["M"]]; const romanNumerals = [["I", "IV", "V", "IX"], ["X", "XL", "L", "XC"], ["C", "CD", "D", "CM"], ["M"]];
const styleList = [ const styleList = [
{ name: "Normal Text", fontFamily: "Calibri", fontSize: 11, fontColor: "#000", bold: false, italic: false }, { name: "Normal Text", fontFamily: "Calibri", fontSize: 11, fontColor: "#f00", bold: false, italic: false },
{ name: "Title", fontFamily: "Calibri", fontSize: 26, fontColor: "#000", bold: false, italic: false }, { name: "Title", fontFamily: "Calibri", fontSize: 26, fontColor: "#0f0", bold: false, italic: false },
{ name: "Subtitle", fontFamily: "Calibri", fontSize: 15, fontColor: "#555", bold: false, italic: false }, { name: "Subtitle", fontFamily: "Calibri", fontSize: 15, fontColor: "#555", bold: false, italic: false },
{ name: "Heading 1", fontFamily: "Calibri", fontSize: 20, fontColor: "#000", bold: false, italic: false }, { name: "Heading 1", fontFamily: "Calibri", fontSize: 20, fontColor: "#00f", bold: false, italic: false },
] ]
const styleName = { };
styleList.forEach( (sty, s)=> { styleName[sty.name] = s } )
var defaultConfig = { var defaultConfig = {
pageSetup: { size: "A4" }, zoom: 1, pageSetup: { size: "A4" }, zoom: 1,
format: { format: {
...@@ -54,7 +58,7 @@ var ADocEditor = function (customConfig) { ...@@ -54,7 +58,7 @@ var ADocEditor = function (customConfig) {
pageIndex: 0, pageIndex: 0,
caretSize: config.style.fontSize, caretSize: config.style.fontSize,
previousCaret: null, previousCaret: null,
style: null, style: { type: "Normal Text" },
dimension: { dimension: {
x: config.format.margin, x: config.format.margin,
y: config.format.margin + (3 * config.style.fontSize / 4) y: config.format.margin + (3 * config.style.fontSize / 4)
...@@ -123,10 +127,10 @@ var ADocEditor = function (customConfig) { ...@@ -123,10 +127,10 @@ var ADocEditor = function (customConfig) {
</div> </div>
<div class="page-list" adc="page-list"></div> <div class="page-list" adc="page-list"></div>
<div class="right-sidebar hide"> <!-- <div class="right-sidebar hide">
<button class="toggle-btn" adc="toggle-right-sidebar">X</button> <button class="toggle-btn" adc="toggle-right-sidebar">X</button>
<div class="content" adc="right-sidebar-content"></div> <div class="content" adc="right-sidebar-content"></div>
</div> </div> -->
</div> </div>
<div class="footer"> <div class="footer">
...@@ -191,13 +195,17 @@ var ADocEditor = function (customConfig) { ...@@ -191,13 +195,17 @@ var ADocEditor = function (customConfig) {
!(function fontSelectHandle() { !(function fontSelectHandle() {
let fontSelect = shadow.querySelector('[adc="font-select"]') let fontSelect = shadow.querySelector('[adc="font-select"]')
headerToolbar.push(fontSelect) let caretStyle = getFullStyle(caretData.style)
fontSelect.value = caretStyle.fontFamily
fontSelect.addEventListener('change', (e) => { fontSelect.addEventListener('change', (e) => {
if (e.target.value){
caretData.style = { caretData.style = {
...caretData.style, ...caretStyle,
fontFamily: e.target.value, fontFamily: e.target.value,
} }
delete caretData.style.type
focusOnPage() focusOnPage()
}
}) })
addFonts(["./assets/fonts/Afacad-VariableFont_wght.woff2", "./assets/fonts/Afacad-VariableFont_wght.ttf"], 'Afacad') addFonts(["./assets/fonts/Afacad-VariableFont_wght.woff2", "./assets/fonts/Afacad-VariableFont_wght.ttf"], 'Afacad')
addFonts(["./assets/fonts/ArchitectsDaughter-Regular.woff2", "./assets/fonts/ArchitectsDaughter-Regular.ttf"], 'Architects Daughter') addFonts(["./assets/fonts/ArchitectsDaughter-Regular.woff2", "./assets/fonts/ArchitectsDaughter-Regular.ttf"], 'Architects Daughter')
...@@ -232,7 +240,8 @@ var ADocEditor = function (customConfig) { ...@@ -232,7 +240,8 @@ var ADocEditor = function (customConfig) {
!(function fontSizeHandler() { !(function fontSizeHandler() {
let fontSizeInput = shadow.querySelector('[adc="font-size-input"]') let fontSizeInput = shadow.querySelector('[adc="font-size-input"]')
fontSizeInput.value = (caretData?.style?caretData:config).style.fontSize let caretStyle = getFullStyle(caretData.style)
fontSizeInput.value = caretStyle.fontSize
let fontSizeChangers = shadow.querySelectorAll('[adc="font-size-change"]') let fontSizeChangers = shadow.querySelectorAll('[adc="font-size-change"]')
fontSizeChangers.forEach(btn => { fontSizeChangers.forEach(btn => {
btn.addEventListener('click', (e) => { btn.addEventListener('click', (e) => {
...@@ -314,12 +323,12 @@ var ADocEditor = function (customConfig) { ...@@ -314,12 +323,12 @@ var ADocEditor = function (customConfig) {
leftSidebar.classList.toggle('hide') leftSidebar.classList.toggle('hide')
}) })
let rightSidebar = shadow.querySelector('.right-sidebar') // let rightSidebar = shadow.querySelector('.right-sidebar')
let toggleRight = shadow.querySelector('[adc="toggle-right-sidebar"]') // let toggleRight = shadow.querySelector('[adc="toggle-right-sidebar"]')
toggleRight.addEventListener('click', ()=>{ // toggleRight.addEventListener('click', ()=>{
rightSidebar.classList.toggle('hide') // rightSidebar.classList.toggle('hide')
toggleRight.scrollIntoView({behavior: 'smooth'}) // toggleRight.scrollIntoView({behavior: 'smooth'})
}) // })
})() })()
...@@ -433,8 +442,7 @@ var ADocEditor = function (customConfig) { ...@@ -433,8 +442,7 @@ var ADocEditor = function (customConfig) {
} }
} }
for (c = 0; c < dataBlock.plainContent.length; c++) { for (c = 0; c < dataBlock.plainContent.length; c++) {
let style = dataBlock?.formatedText?.[c].style let style = getFullStyle(dataBlock?.formatedText?.[c].style)
if (!style) style = { ...config.style }
lineObj.maxFontSize = (lineObj.maxFontSize < style.fontSize) ? style.fontSize : lineObj.maxFontSize lineObj.maxFontSize = (lineObj.maxFontSize < style.fontSize) ? style.fontSize : lineObj.maxFontSize
if (/\s/.test(dataBlock.plainContent[c])) { if (/\s/.test(dataBlock.plainContent[c])) {
...@@ -445,15 +453,7 @@ var ADocEditor = function (customConfig) { ...@@ -445,15 +453,7 @@ var ADocEditor = function (customConfig) {
} }
let charWidth = getCharacterWidth(dataBlock.plainContent[c], style) let charWidth = getCharacterWidth(dataBlock.plainContent[c], style)
dataBlock.formatedText[c] = { dataBlock.formatedText[c].dimension.width = charWidth
style: {
...config.style,
...style,
},
dimension: {
width: charWidth,
},
}
// // if with the current char the string could not fit on one line // // if with the current char the string could not fit on one line
if (tempLineWidth + charWidth > maxLineWidth) { if (tempLineWidth + charWidth > maxLineWidth) {
...@@ -541,9 +541,10 @@ var ADocEditor = function (customConfig) { ...@@ -541,9 +541,10 @@ var ADocEditor = function (customConfig) {
// this is to render the numbering and bullets etc // this is to render the numbering and bullets etc
if (lines[l].dataType == 1) { if (lines[l].dataType == 1) {
let setStyle = getFullStyle(setData.style)
ctx.save() ctx.save()
ctx.font = `${setData.style.fontSize * pxMmRatio * mmPtRatio}px ${setData.style.fontFamily}` ctx.font = `${setStyle.fontSize * pxMmRatio * mmPtRatio}px ${setStyle.fontFamily}`
ctx.fillStyle = `${setData.style.fontColor}` ctx.fillStyle = `${setStyle.fontColor}`
let label = getLabel(lines[l].dataIndex) let label = getLabel(lines[l].dataIndex)
let labelWidth = ctx.measureText(label).width let labelWidth = ctx.measureText(label).width
labelWidth += mmPtRatio * pxMmRatio * 5 labelWidth += mmPtRatio * pxMmRatio * 5
...@@ -557,7 +558,7 @@ var ADocEditor = function (customConfig) { ...@@ -557,7 +558,7 @@ var ADocEditor = function (customConfig) {
for (let c = lines[l].charStartIndex; c <= lines[l].charEndIndex; c++) { for (let c = lines[l].charStartIndex; c <= lines[l].charEndIndex; c++) {
let char = setData?.plainContent[c] let char = setData?.plainContent[c]
if (char) { if (char) {
let style = setData.formatedText[c].style let style = getFullStyle(setData.formatedText[c].style)
ctx.save() ctx.save()
ctx.font = `${style?.bold ? 'bold ' : ''}${style?.italic ? 'italic ' : ''} ${style.fontSize * pxMmRatio * mmPtRatio}px ${style.fontFamily}` ctx.font = `${style?.bold ? 'bold ' : ''}${style?.italic ? 'italic ' : ''} ${style.fontSize * pxMmRatio * mmPtRatio}px ${style.fontFamily}`
ctx.fillStyle = `${style?.fontColor}` ctx.fillStyle = `${style?.fontColor}`
...@@ -681,7 +682,6 @@ var ADocEditor = function (customConfig) { ...@@ -681,7 +682,6 @@ var ADocEditor = function (customConfig) {
caretData.activeData.plainContent = caretData.activeData.plainContent.slice(0, caretData.index) + e.key + caretData.activeData.plainContent.slice(caretData.index) caretData.activeData.plainContent = caretData.activeData.plainContent.slice(0, caretData.index) + e.key + caretData.activeData.plainContent.slice(caretData.index)
let style = caretData.style let style = caretData.style
style = style?style:null style = style?style:null
console.log(style)
caretData.activeData.formatedText.splice(caretData.index, 0, { style : style, dimension: {} }) caretData.activeData.formatedText.splice(caretData.index, 0, { style : style, dimension: {} })
++caretData.index ++caretData.index
} }
...@@ -768,7 +768,9 @@ var ADocEditor = function (customConfig) { ...@@ -768,7 +768,9 @@ var ADocEditor = function (customConfig) {
...caretData.style, ...caretData.style,
fontSize: style.fontSize, fontSize: style.fontSize,
} }
shadow.querySelector('[adc="font-size-input"]').value = caretData.style.fontSize let fontInput = shadow.querySelector('[adc="font-size-input"]')
if (caretData?.style?.fontSize) fontInput.value = caretData.style.fontSize
else if (style?.fontSize) fontInput.value = style.fontSize
} }
} }
function onFocusHandler(e) { function onFocusHandler(e) {
...@@ -886,7 +888,7 @@ var ADocEditor = function (customConfig) { ...@@ -886,7 +888,7 @@ var ADocEditor = function (customConfig) {
} }
function reRenderFontDropdown() { function reRenderFontDropdown() {
let fontFamilyDropdown = headerToolbar.find(item => item.getAttribute('adc') == 'font-select') let fontFamilyDropdown = shadow.querySelector('[adc="font-select"]')
if (fontFamilyDropdown) { if (fontFamilyDropdown) {
fontFamilyDropdown.innerHTML = "" fontFamilyDropdown.innerHTML = ""
fontList.forEach((font, i) => { fontList.forEach((font, i) => {
...@@ -901,8 +903,9 @@ var ADocEditor = function (customConfig) { ...@@ -901,8 +903,9 @@ var ADocEditor = function (customConfig) {
} }
function changeFontFamily() { function changeFontFamily() {
let fontFamilyDropdown = headerToolbar.find(item => item.getAttribute('adc') == 'font-select') let fontFamilyDropdown = shadow.querySelector('[adc="font-select"]')
if (fontFamilyDropdown) fontFamilyDropdown.value = (caretData?.style?caretData:config).style.fontFamily let caretStyle = getFullStyle(caretData.style)
if (fontFamilyDropdown) fontFamilyDropdown.value = caretStyle.fontFamily
} }
} }
...@@ -951,6 +954,17 @@ var ADocEditor = function (customConfig) { ...@@ -951,6 +954,17 @@ var ADocEditor = function (customConfig) {
} }
} }
function getFullStyle(refStyle){
let style = { }
if (refStyle.type){
style = { ...styleList[styleName[refStyle.type] ] }
}
style = { ...style, ...refStyle }
style = JSON.parse( JSON.stringify(style) )
if (Object.keys(style).length > 1) delete style.type
return style
}
function renderCaret(toLoop) { function renderCaret(toLoop) {
clearTimeout(caretData.timeout) clearTimeout(caretData.timeout)
...@@ -971,14 +985,15 @@ var ADocEditor = function (customConfig) { ...@@ -971,14 +985,15 @@ var ADocEditor = function (customConfig) {
let x = (config.format.margin * pxMmRatio) + lineObj.tabWidth let x = (config.format.margin * pxMmRatio) + lineObj.tabWidth
let y = (config.format.margin) * pxMmRatio let y = (config.format.margin) * pxMmRatio
let height = (caretData?.style?caretData:config).style.fontSize * pxMmRatio * mmPtRatio * 5 / 4 let caretStyle = getFullStyle(caretData.style)
let height = caretStyle.fontSize * pxMmRatio * mmPtRatio * 5 / 4
let width = height / 10 let width = height / 10
let charDimension = caretData.activeData.formatedText[caretData.index - 1]?.dimension let charDimension = caretData.activeData.formatedText[caretData.index - 1]?.dimension
if (lineObj) { if (lineObj) {
x = (charDimension ? (charDimension.x + charDimension.width) : x) x = (charDimension ? (charDimension.x + charDimension.width) : x)
if (charDimension) { if (charDimension) {
y = charDimension.y - ((caretData?.style?caretData:config).style.fontSize * pxMmRatio * mmPtRatio) y = charDimension.y - (caretStyle.fontSize * pxMmRatio * mmPtRatio)
} else { } else {
if (prevLine && prevLine.pageIndex != lineObj.pageIndex) { if (prevLine && prevLine.pageIndex != lineObj.pageIndex) {
y = (config.format.margin) * pxMmRatio y = (config.format.margin) * pxMmRatio
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment