-
Notifications
You must be signed in to change notification settings - Fork 77
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
10 changed files
with
384 additions
and
15,923 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 |
---|---|---|
|
@@ -8,7 +8,7 @@ jobs: | |
|
||
strategy: | ||
matrix: | ||
node-version: [18.x] | ||
node-version: [20.x] | ||
|
||
steps: | ||
- name: Checkout | ||
|
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 |
---|---|---|
@@ -0,0 +1,58 @@ | ||
'use client'; | ||
|
||
import React, { useRef, useEffect } from 'react'; | ||
import domAlign from '../../src'; | ||
|
||
export default function Overflow() { | ||
const source = useRef(); | ||
const target = useRef(); | ||
const timer = useRef<any>(); | ||
const align = () => { | ||
const ret = domAlign(source.current, target.current, { | ||
points: ['tl', 'bl'], | ||
overflow: { | ||
adjustY: 1, | ||
adjustX: 1, | ||
}, | ||
}); | ||
console.log(ret); | ||
if (timer.current) { | ||
clearTimeout(timer.current); | ||
} | ||
timer.current = setTimeout(() => { | ||
document.body.style.overflow = 'hidden'; | ||
}, 1000); | ||
}; | ||
|
||
useEffect(() => { | ||
return () => { | ||
if (timer.current) { | ||
clearTimeout(timer.current); | ||
} | ||
document.body.style.overflow = ''; | ||
}; | ||
}, []); | ||
|
||
return ( | ||
<div style={{ height: 1000 }}> | ||
<button ref={target} style={{ position: 'absolute', right: 0, top: 300 }}> | ||
target | ||
</button> | ||
|
||
<div style={{ height: 100 }} /> | ||
|
||
<button onClick={align}>align</button> | ||
|
||
<div | ||
ref={source} | ||
style={{ | ||
position: 'absolute', | ||
width: 100, | ||
height: 200, | ||
border: '1px solid red', | ||
}}> | ||
oo | ||
</div> | ||
</div> | ||
); | ||
} |
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 |
---|---|---|
@@ -0,0 +1,39 @@ | ||
'use client'; | ||
|
||
import React, { useRef, useEffect } from 'react'; | ||
import domAlign from '../../src'; | ||
|
||
export default function Fail() { | ||
const source = useRef(); | ||
const target = useRef(); | ||
|
||
function align() { | ||
const ret = domAlign(source.current, target.current, { | ||
points: ['bl', 'bl'], | ||
overflow: { | ||
adjustY: 1, | ||
}, | ||
}); | ||
console.log(ret); | ||
} | ||
return ( | ||
<div style={{ height: 1000 }}> | ||
<button ref={target}>target</button> | ||
|
||
<div style={{ height: 100 }} /> | ||
|
||
<button onClick={align}>align</button> | ||
|
||
<div | ||
ref={source} | ||
style={{ | ||
position: 'absolute', | ||
width: 100, | ||
height: 200, | ||
border: '1px solid red', | ||
}}> | ||
oo | ||
</div> | ||
</div> | ||
); | ||
} |
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 |
---|---|---|
@@ -0,0 +1,60 @@ | ||
import Link from 'next/link'; | ||
import { useMemo } from 'react'; | ||
import React from 'react'; | ||
import MarkdownIt from 'markdown-it'; | ||
import 'github-markdown-css/github-markdown-light.css'; | ||
// @ts-ignore | ||
import prism from 'prismjs'; | ||
import 'prismjs/components/prism-json'; | ||
import 'prismjs/components/prism-javascript'; | ||
import 'prismjs/themes/prism.css'; | ||
import fs from 'fs'; | ||
import path from 'path'; | ||
|
||
const readme = fs.readFileSync( | ||
path.join(process.cwd(), './README.md'), | ||
'utf-8', | ||
); | ||
const md = new MarkdownIt({ | ||
html: true, | ||
linkify: true, | ||
typographer: true, | ||
highlight: function (code, lang) { | ||
if (prism.languages[lang]) { | ||
return prism.highlight(code, prism.languages[lang], lang); | ||
} else { | ||
return code; | ||
} | ||
}, | ||
}); | ||
|
||
export default function Home() { | ||
const content = useMemo(() => { | ||
return md.render(readme); | ||
}, []); | ||
|
||
return ( | ||
<div style={{ width: 1200, margin: 'auto' }}> | ||
<h2>examples</h2> | ||
<p> | ||
<Link href="/simple">simple</Link> | ||
</p> | ||
<p> | ||
<Link href="/body-overflow">body-overflow</Link> | ||
</p> | ||
<p> | ||
<Link href="/fail">fail</Link> | ||
</p> | ||
<p> | ||
<Link href="/point">point</Link> | ||
</p> | ||
<p> | ||
<Link href="/shadow-dom">shadow-dom</Link> | ||
</p> | ||
<h2>readme</h2> | ||
<div | ||
className="markdown-body" | ||
dangerouslySetInnerHTML={{ __html: content }}></div> | ||
</div> | ||
); | ||
} |
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 |
---|---|---|
@@ -0,0 +1,51 @@ | ||
'use client'; | ||
|
||
import React, { useRef, useEffect } from 'react'; | ||
import ReactDOM from 'react-dom/client'; | ||
import domAlign from '../../src'; | ||
|
||
function Test() { | ||
const source = useRef(); | ||
const target = useRef(); | ||
function align() { | ||
const ret = domAlign(source.current, target.current, { | ||
points: ['bl', 'bl'], | ||
overflow: { | ||
adjustY: 1, | ||
}, | ||
}); | ||
console.log(ret); | ||
} | ||
|
||
return ( | ||
<div style={{ height: 1000 }}> | ||
<button ref={target}>target</button> | ||
|
||
<div style={{ height: 100 }} /> | ||
|
||
<button onClick={align}>align</button> | ||
|
||
<div | ||
ref={source} | ||
style={{ | ||
position: 'absolute', | ||
width: 100, | ||
height: 200, | ||
border: '1px solid red', | ||
}}> | ||
oo | ||
</div> | ||
</div> | ||
); | ||
} | ||
|
||
export default function ShadowDom() { | ||
const source = useRef<HTMLDivElement>(); | ||
|
||
useEffect(() => { | ||
const shadowRoot = source.current.attachShadow({ mode: 'open' }); | ||
ReactDOM.createRoot(shadowRoot).render(<Test />); | ||
}, []); | ||
|
||
return <div ref={source}></div>; | ||
} |
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 |
---|---|---|
@@ -0,0 +1,148 @@ | ||
'use client'; | ||
|
||
import React from 'react'; | ||
import domAlign from '../../src'; | ||
|
||
function $id(id): any { | ||
return document.getElementById(id); | ||
} | ||
|
||
function $val(sel) { | ||
sel = $id(sel); | ||
return sel.value; | ||
} | ||
|
||
function align() { | ||
domAlign($id('source'), $id('target'), { | ||
points: [ | ||
$val('source_align_tb') + $val('source_align_lr'), | ||
$val('target_align_tb') + $val('target_align_lr'), | ||
], | ||
offset: [$val('offset1'), $val('offset2')], | ||
targetOffset: [$val('targetOffset1'), $val('targetOffset2')], | ||
overflow: { | ||
adjustX: $id('adjustX').checked, | ||
adjustY: $id('adjustY').checked, | ||
}, | ||
useCssRight: $id('useCssRight').checked, | ||
useCssBottom: $id('useCssBottom').checked, | ||
useCssTransform: $id('useCssTransform').checked, | ||
|
||
ignoreShake: $id('ignoreShake').checked, | ||
}); | ||
} | ||
export default function Simple() { | ||
return ( | ||
<div> | ||
<h1>dom-align</h1> | ||
|
||
<div> | ||
source: | ||
<select id="source_align_tb"> | ||
<option value="t">t</option> | ||
<option value="c">c</option> | ||
<option value="b">b</option> | ||
</select> | ||
<select id="source_align_lr"> | ||
<option value="l">l</option> | ||
<option value="c">c</option> | ||
<option value="r">r</option> | ||
</select> | ||
target: | ||
<select id="target_align_tb"> | ||
<option value="t">t</option> | ||
<option value="c">c</option> | ||
<option value="b">b</option> | ||
</select> | ||
<select id="target_align_lr"> | ||
<option value="l">l</option> | ||
<option value="c">c</option> | ||
<option value="r">r</option> | ||
</select> | ||
offset: [ | ||
<input type="offset" id="offset1" defaultValue="0" size={3} /> | ||
, | ||
<input type="offset" id="offset2" defaultValue="0" size={3} /> | ||
] targetOffset: [ | ||
<input type="offset" id="targetOffset1" defaultValue="0" size={3} /> | ||
, | ||
<input type="offset" id="targetOffset2" defaultValue="0" size={3} />] | ||
overflow: | ||
<label> | ||
adjustX: | ||
<input type="checkbox" id="adjustX" /> | ||
</label> | ||
| ||
<label> | ||
adjustY: | ||
<input type="checkbox" id="adjustY" /> | ||
</label> | ||
| ||
<label> | ||
useCssBottom: | ||
<input type="checkbox" id="useCssBottom" /> | ||
</label> | ||
| ||
<label> | ||
useCssRight: | ||
<input type="checkbox" id="useCssRight" /> | ||
</label> | ||
| ||
<label> | ||
useCssTransform: | ||
<input type="checkbox" id="useCssTransform" defaultChecked={false} /> | ||
</label> | ||
| ||
<label> | ||
ignoreShake: | ||
<input type="checkbox" id="ignoreShake" /> | ||
</label> | ||
| ||
<button id="align" onClick={align}> | ||
align | ||
</button> | ||
<br /> | ||
<div | ||
style={{ | ||
width: 400, | ||
height: 400, | ||
overflow: 'auto', | ||
border: '1px solid green', | ||
position: 'relative', | ||
}}> | ||
<div | ||
style={{ | ||
background: 'yellow', | ||
width: 240, | ||
height: 240, | ||
margin: 50, | ||
}} | ||
id="target"> | ||
target node | ||
</div> | ||
<div style={{ width: 1000, height: 1000 }} /> | ||
<div | ||
style={{ | ||
background: 'red', | ||
width: 80, | ||
height: 80, | ||
left: 0, | ||
top: 0, | ||
position: 'absolute', | ||
transition: 'all 0.5s', | ||
overflowY: 'auto', | ||
}} | ||
id="source"> | ||
source node | ||
<br /> | ||
<br /> | ||
<br /> | ||
<br /> | ||
<br /> | ||
<br /> | ||
</div> | ||
</div> | ||
</div> | ||
</div> | ||
); | ||
} |
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
Oops, something went wrong.