Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
A
a-doc-editor
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Ramdayal Munda
a-doc-editor
Commits
d811b5b2
Commit
d811b5b2
authored
Jan 09, 2024
by
ramdayalmunda
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
new change
parent
eb8354a1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
92 additions
and
40 deletions
+92
-40
a-doc-editor2.js
dist/assets/a-doc-editor2.js
+92
-40
No files found.
dist/assets/a-doc-editor2.js
View file @
d811b5b2
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
,
shadow
,
pxMmRatio
,
configuration
,
htmlStr
,
htmlTag
,
htmlObj
=
{},
fontList
=
[],
headerToolbar
=
[];
var
container
,
counter
=
0
,
shadow
,
pxMmRatio
,
config
,
htmlStr
,
htmlTag
,
htmlObj
=
{},
fontList
=
[],
headerToolbar
=
[];
var
paperSizes
=
{
var
paperSizes
=
{
"A4"
:
{
mmWidth
:
210
,
mmHeight
:
297
},
"A4"
:
{
mmWidth
:
210
,
mmHeight
:
297
},
}
}
var
defaultConfig
=
{
var
defaultConfig
=
{
pageSetup
:
{
size
:
"A4"
},
zoom
:
1
,
pageSetup
:
{
size
:
"A4"
},
zoom
:
1
,
format
:
{
background
:
"#fff"
,
margin
:
20
,
border
:
""
,
tabWidth
:
20
,
},
style
:
{
fontSize
:
16
,
fontFamily
:
'Calibri'
,
bold
:
false
,
italic
:
false
,
fontColor
:
"#001"
},
}
}
var
pageList
=
[]
var
pageList
=
[]
var
isRendering
=
false
function
initialize
()
{
function
initialize
()
{
config
uration
=
JSON
.
parse
(
JSON
.
stringify
(
defaultConfig
))
config
=
JSON
.
parse
(
JSON
.
stringify
(
defaultConfig
))
container
=
customConfig
.
container
container
=
customConfig
.
container
shadow
=
container
.
attachShadow
({
mode
:
"open"
})
shadow
=
container
.
attachShadow
({
mode
:
"open"
})
...
@@ -70,15 +84,15 @@ var ADocEditor = function (customConfig) {
...
@@ -70,15 +84,15 @@ var ADocEditor = function (customConfig) {
!
(
function
zoomHandles
()
{
!
(
function
zoomHandles
()
{
let
zoomSelect
=
shadow
.
querySelector
(
'[adc="zoom"]'
)
let
zoomSelect
=
shadow
.
querySelector
(
'[adc="zoom"]'
)
zoomSelect
.
addEventListener
(
'change'
,
(
e
)
=>
{
zoomSelect
.
addEventListener
(
'change'
,
(
e
)
=>
{
config
uration
.
zoom
=
Number
(
e
.
target
.
value
)
config
.
zoom
=
Number
(
e
.
target
.
value
)
reConfigure
(
config
uration
)
reConfigure
(
config
)
})
})
})()
})()
!
(
function
fontSelectHandle
()
{
!
(
function
fontSelectHandle
()
{
let
fontSelect
=
shadow
.
querySelector
(
'[adc="font-select"]'
)
let
fontSelect
=
shadow
.
querySelector
(
'[adc="font-select"]'
)
headerToolbar
.
push
(
fontSelect
)
headerToolbar
.
push
(
fontSelect
)
fontSelect
.
addEventListener
(
'change'
,
(
e
)
=>
{
fontSelect
.
addEventListener
(
'change'
,
(
e
)
=>
{
console
.
log
(
'font'
,
e
.
target
.
value
)
console
.
log
(
'font'
,
e
.
target
.
value
)
})
})
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'
)
...
@@ -122,31 +136,31 @@ var ADocEditor = function (customConfig) {
...
@@ -122,31 +136,31 @@ var ADocEditor = function (customConfig) {
})()
})()
reConfigure
(
customConfig
)
reConfigure
(
customConfig
)
createNewPage
(
0
)
reRenderCanvas
(
)
}
}
function
reConfigure
(
newConfig
)
{
function
reConfigure
(
newConfig
)
{
if
(
newConfig
?.
size
&&
paperSizes
[
newConfig
?.
size
])
{
config
uration
.
pageSetup
=
{
...
paperSizes
[
newConfig
.
size
],
size
:
newConfig
.
size
}
}
if
(
newConfig
?.
size
&&
paperSizes
[
newConfig
?.
size
])
{
config
.
pageSetup
=
{
...
paperSizes
[
newConfig
.
size
],
size
:
newConfig
.
size
}
}
else
if
(
newConfig
?.
width
&&
newConfig
?.
height
)
{
else
if
(
newConfig
?.
width
&&
newConfig
?.
height
)
{
config
uration
.
pageSetup
=
{
size
:
"Custom"
,
mmWidth
:
newConfig
.
width
,
mmHeight
:
newConfig
.
height
}
config
.
pageSetup
=
{
size
:
"Custom"
,
mmWidth
:
newConfig
.
width
,
mmHeight
:
newConfig
.
height
}
}
}
else
{
config
uration
.
pageSetup
=
{
size
:
"A4"
,
...
paperSizes
[
'A4'
]
}
}
else
{
config
.
pageSetup
=
{
size
:
"A4"
,
...
paperSizes
[
'A4'
]
}
}
if
(
typeof
window
==
'object'
)
{
if
(
typeof
window
==
'object'
)
{
config
uration
.
pageSetup
.
multipler
=
configuration
.
pageSetup
.
mmHeight
/
configuration
.
pageSetup
.
mmWidth
config
.
pageSetup
.
multipler
=
config
.
pageSetup
.
mmHeight
/
config
.
pageSetup
.
mmWidth
config
uration
.
pageSetup
.
pxWidth
=
2480
config
.
pageSetup
.
pxWidth
=
2480
config
uration
.
pageSetup
.
pxHeight
=
Math
.
ceil
(
configuration
.
pageSetup
.
pxWidth
*
configuration
.
pageSetup
.
multipler
)
config
.
pageSetup
.
pxHeight
=
Math
.
ceil
(
config
.
pageSetup
.
pxWidth
*
config
.
pageSetup
.
multipler
)
}
else
{
}
else
{
config
uration
.
pageSetup
.
pxHeight
=
configuration
.
pageSetup
.
mmHeight
config
.
pageSetup
.
pxHeight
=
config
.
pageSetup
.
mmHeight
config
uration
.
pageSetup
.
pxWidth
=
configuration
.
pageSetup
.
mmWidth
config
.
pageSetup
.
pxWidth
=
config
.
pageSetup
.
mmWidth
}
}
if
(
config
uration
.
zoom
)
{
if
(
config
.
zoom
)
{
config
uration
.
pageSetup
.
uiWidth
=
configuration
.
pageSetup
.
mmWidth
*
configuration
.
zoom
config
.
pageSetup
.
uiWidth
=
config
.
pageSetup
.
mmWidth
*
config
.
zoom
config
uration
.
pageSetup
.
uiHeight
=
configuration
.
pageSetup
.
mmHeight
*
configuration
.
zoom
config
.
pageSetup
.
uiHeight
=
config
.
pageSetup
.
mmHeight
*
config
.
zoom
}
}
for
(
let
p
=
0
;
p
<
pageList
.
length
;
p
++
)
{
for
(
let
p
=
0
;
p
<
pageList
.
length
;
p
++
)
{
pageList
[
p
].
canvas
.
style
.
width
=
`
${
config
uration
.
pageSetup
.
uiWidth
}
mm`
pageList
[
p
].
canvas
.
style
.
width
=
`
${
config
.
pageSetup
.
uiWidth
}
mm`
}
}
let
scale
=
shadow
.
querySelector
(
'.scale'
)
let
scale
=
shadow
.
querySelector
(
'.scale'
)
...
@@ -154,26 +168,64 @@ var ADocEditor = function (customConfig) {
...
@@ -154,26 +168,64 @@ var ADocEditor = function (customConfig) {
let
rect
=
scale
.
getBoundingClientRect
()
let
rect
=
scale
.
getBoundingClientRect
()
pxMmRatio
=
rect
.
width
/
100
;
pxMmRatio
=
rect
.
width
/
100
;
return
config
uration
return
config
}
}
function
createNewPage
(
index
)
{
function
reRenderCanvas
(
)
{
let
pageObj
=
{
console
.
log
(
'to rerender the page'
)
canvas
:
null
,
if
(
isRendering
)
return
firstDataIndex
:
null
,
let
pageIndex
=
0
firstCharIndex
:
null
,
if
(
!
pageList
.
length
)
{
lastDataIndex
:
null
,
pageList
[
pageIndex
]
=
{
id
:
++
counter
,
el
:
createNewPage
(),
dataIndex
:
0
}
lastCharIndex
:
null
shadow
.
querySelector
(
'.page-list'
).
append
(
pageList
[
pageIndex
].
el
)
}
}
if
(
!
isModule
)
{
pageObj
.
canvas
=
document
.
createElement
(
'canvas'
)
pageObj
.
canvas
.
setAttribute
(
'tabIndex'
,
'-1'
)
// to clear the canvases
pageObj
.
canvas
.
width
=
configuration
.
pageSetup
.
pxWidth
for
(
let
i
=
0
;
i
<
pageList
.
length
;
i
++
)
{
pageObj
.
canvas
.
height
=
configuration
.
pageSetup
.
pxHeight
let
ctx
=
pageList
[
i
].
el
.
getContext
(
'2d'
,
{
willReadFrequently
:
true
})
pageList
.
push
(
pageObj
)
ctx
.
save
()
pageObj
.
canvas
.
style
.
width
=
`
${
configuration
.
pageSetup
.
uiWidth
}
mm`
ctx
.
clearRect
(
0
,
0
,
pageList
[
i
].
el
.
width
,
pageList
[
i
].
el
.
height
);
// clears the canvas
shadow
.
querySelector
(
'.page-list'
).
append
(
pageObj
.
canvas
)
ctx
.
fillStyle
=
config
.
format
.
background
ctx
.
fillRect
(
0
,
0
,
pageList
[
i
].
el
.
width
,
pageList
[
i
].
el
.
height
)
ctx
.
restore
()
}
}
}
function
createNewPage
()
{
let
canvas
;
if
(
isModule
)
{
const
{
createCanvas
}
=
require
(
'canvas'
)
canvas
=
createCanvas
(
config
.
pageSetup
.
canvasWidth
,
config
.
pageSetup
.
canvasHeight
)
}
else
{
canvas
=
document
.
createElement
(
'canvas'
)
canvas
.
setAttribute
(
'class'
,
'page'
)
canvas
.
width
=
config
.
pageSetup
.
canvasWidth
canvas
.
height
=
config
.
pageSetup
.
canvasHeight
canvas
.
setAttribute
(
"tabIndex"
,
-
1
)
canvas
.
setAttribute
(
'tabIndex'
,
'-1'
)
canvas
.
width
=
config
.
pageSetup
.
pxWidth
canvas
.
height
=
config
.
pageSetup
.
pxHeight
canvas
.
style
.
width
=
`
${
config
.
pageSetup
.
uiWidth
}
mm`
let
ctx
=
canvas
.
getContext
(
'2d'
,
{
willReadFrequently
:
true
})
console
.
log
(
'conf'
,
config
)
ctx
.
fillStyle
=
config
.
format
.
background
ctx
.
fillRect
(
0
,
0
,
canvas
.
width
,
canvas
.
height
)
canvas
.
addEventListener
(
'keydown'
,
keydownHandler
)
// canvas.addEventListener('mousedown', mousedownHandler)
// canvas.addEventListener("focus", onFocusHandler)
// canvas.addEventListener("blur", onBlurHandler)
}
return
canvas
}
function
keydownHandler
(
e
)
{
console
.
log
(
`
${(
e
.
shiftKey
&&
e
.
key
!=
'Shift'
)
?
'Shift+'
:
''
}${(
e
.
ctrlKey
&&
e
.
key
!=
'Ctrl'
)
?
'Ctrl+'
:
''
}${
e
.
key
}
`
)
}
}
...
@@ -205,7 +257,7 @@ var ADocEditor = function (customConfig) {
...
@@ -205,7 +257,7 @@ var ADocEditor = function (customConfig) {
}
}
function
reRenderFontDropdown
()
{
function
reRenderFontDropdown
()
{
let
fontFamilyDropdown
=
headerToolbar
.
find
(
item
=>
item
.
getAttribute
(
'adc'
)
==
'font-select'
)
let
fontFamilyDropdown
=
headerToolbar
.
find
(
item
=>
item
.
getAttribute
(
'adc'
)
==
'font-select'
)
if
(
fontFamilyDropdown
)
{
if
(
fontFamilyDropdown
)
{
fontFamilyDropdown
.
innerHTML
=
""
fontFamilyDropdown
.
innerHTML
=
""
fontList
.
forEach
((
font
,
i
)
=>
{
fontList
.
forEach
((
font
,
i
)
=>
{
...
@@ -217,7 +269,7 @@ var ADocEditor = function (customConfig) {
...
@@ -217,7 +269,7 @@ var ADocEditor = function (customConfig) {
})
})
}
}
// changeFontFamily()
// changeFontFamily()
}
}
}
}
...
@@ -225,10 +277,10 @@ var ADocEditor = function (customConfig) {
...
@@ -225,10 +277,10 @@ var ADocEditor = function (customConfig) {
var
returnObj
=
{
var
returnObj
=
{
addFonts
,
addFonts
,
getConfiguration
()
{
return
JSON
.
parse
(
JSON
.
stringify
(
configuration
)
)
},
getConfiguration
()
{
return
JSON
.
parse
(
JSON
.
stringify
(
config
)
)
},
getPages
(){
getPages
()
{
let
pagesToReturn
=
JSON
.
parse
(
JSON
.
stringify
(
pageList
)
)
let
pagesToReturn
=
JSON
.
parse
(
JSON
.
stringify
(
pageList
)
)
for
(
let
i
=
0
;
i
<
pagesToReturn
.
length
;
i
++
)
pagesToReturn
[
i
].
canvas
=
pageList
[
i
].
canvas
for
(
let
i
=
0
;
i
<
pagesToReturn
.
length
;
i
++
)
pagesToReturn
[
i
].
canvas
=
pageList
[
i
].
canvas
return
pagesToReturn
return
pagesToReturn
},
},
}
}
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment