Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
L
leximpact-legi-ui
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Container registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
GitLab community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
leximpact
Exploration
leximpact-legi-ui
Commits
e70fbe6a
Commit
e70fbe6a
authored
2 months ago
by
David Smadja
Browse files
Options
Downloads
Patches
Plain Diff
Resize images and fonts according to container width to keep ratio with text section
parent
8041eee2
No related branches found
No related tags found
1 merge request
!1
Temp
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
src/lib/components/Bill.svelte
+53
-11
53 additions, 11 deletions
src/lib/components/Bill.svelte
with
53 additions
and
11 deletions
src/lib/components/Bill.svelte
+
53
−
11
View file @
e70fbe6a
...
...
@@ -4,6 +4,39 @@
}
let
container
:
HTMLDivElement
let
{
billHTML
}:
Props
=
$props
()
let
resizeObserver
:
ResizeObserver
const
baseWidth
=
800
const
adjustSizes
=
(
shadowRoot
:
ShadowRoot
)
=>
{
if
(
!
shadowRoot
)
return
const
currentWidth
=
shadowRoot
.
host
.
clientWidth
const
scaleFactor
=
Math
.
min
(
1.5
,
currentWidth
/
baseWidth
)
// Limite l'agrandissement
// Applique le facteur d'échelle
const
body
=
shadowRoot
.
querySelector
(
"
body
"
)
if
(
body
)
{
body
.
style
.
fontSize
=
`
${
scaleFactor
*
100
}
%`
body
.
style
.
width
=
`
${
baseWidth
}
px`
// Maintient la largeur de référence
}
// Ajuste les images
shadowRoot
.
querySelectorAll
(
"
img
"
).
forEach
((
img
)
=>
{
const
originalWidth
=
parseInt
(
img
.
dataset
.
originalWidth
||
img
.
getAttribute
(
"
width
"
)
||
"
0
"
,
)
if
(
originalWidth
)
{
const
newWidth
=
originalWidth
*
scaleFactor
img
.
style
.
width
=
`
${
newWidth
}
px`
img
.
style
.
height
=
"
auto
"
img
.
style
.
maxWidth
=
"
none
"
img
.
style
.
display
=
"
block
"
img
.
style
.
margin
=
"
0 auto
"
}
})
}
const
scrollToAnchor
=
(
hash
:
string
,
shadowRoot
:
ShadowRoot
)
=>
{
if
(
!
hash
)
return
...
...
@@ -21,6 +54,13 @@
if
(
!
container
.
shadowRoot
)
{
const
shadow
=
container
.
attachShadow
({
mode
:
"
open
"
})
const
processedHTML
=
billHTML
.
replace
(
/<img
([^
>
]
*
)
width="
([^
"
]
+
)
"
([^
>
]
*
)
>/g
,
(
match
,
before
,
width
,
after
)
=>
{
return
`<img
${
before
}
width="
${
width
}
" data-original-width="
${
width
}
"
${
after
}
>`
},
)
shadow
.
innerHTML
=
`
<style>
:host {
...
...
@@ -31,29 +71,32 @@
padding: 0 16px;
}
body {
width:
100% !important
;
max-width:
8
00
px; /* 600pt ≈ 800px */
width:
${
baseWidth
}
px
;
max-width:
1
00
%;
margin: 0 auto !important;
transform-origin: top center;
}
img {
display: block !important;
max-width: 100% !important;
height: auto !important;
margin-left: auto !important;
margin-right: auto !important;
margin: 0 auto !important;
}
img[width], img[height] {
width: auto !important;
height: auto
!important;
p[style*="text-align:center"] img,
p[style*="text-align: center"] img {
display: inline-block
!important;
}
.content-wrapper {
position: relative;
min-height: 100%;
}
</style>
<div class="content-wrapper">
${
bill
HTML
}
</div>
<div class="content-wrapper">
${
processed
HTML
}
</div>
`
resizeObserver
=
new
ResizeObserver
(()
=>
adjustSizes
(
shadow
))
resizeObserver
.
observe
(
container
)
requestAnimationFrame
(()
=>
adjustSizes
(
shadow
))
scrollToAnchor
(
window
.
location
.
hash
,
shadow
)
shadow
.
addEventListener
(
"
click
"
,
(
e
)
=>
{
const
link
=
(
e
.
target
as
HTMLElement
).
closest
(
'
a[href^="#"]
'
)
...
...
@@ -70,9 +113,8 @@
const
wrapper
=
container
.
shadowRoot
!
.
querySelector
(
"
.content-wrapper
"
)
if
(
wrapper
)
wrapper
.
innerHTML
=
billHTML
}
return
()
=>
resizeObserver
?.
disconnect
()
})
let
{
billHTML
}:
Props
=
$props
()
</script>
<div
bind:this=
{
container
}
class=
"block h-full w-full"
></div>
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment