|
| 1 | +<!DOCTYPE html> |
| 2 | +<html lang="zh-TW"> |
| 3 | +<head> |
| 4 | + <meta charset="UTF-8"> |
| 5 | + <meta name="viewport" content="width=device-width, initial-scale=1.0"> |
| 6 | + <title>pangu.js Browser Example</title> |
| 7 | + <style> |
| 8 | + body { |
| 9 | + font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif; |
| 10 | + max-width: 800px; |
| 11 | + margin: 50px auto; |
| 12 | + padding: 20px; |
| 13 | + line-height: 1.6; |
| 14 | + } |
| 15 | + .example { |
| 16 | + background: #f5f5f5; |
| 17 | + padding: 15px; |
| 18 | + border-radius: 5px; |
| 19 | + margin: 20px 0; |
| 20 | + } |
| 21 | + button { |
| 22 | + background: #007bff; |
| 23 | + color: white; |
| 24 | + border: none; |
| 25 | + padding: 10px 20px; |
| 26 | + border-radius: 5px; |
| 27 | + cursor: pointer; |
| 28 | + margin: 5px; |
| 29 | + } |
| 30 | + button:hover { |
| 31 | + background: #0056b3; |
| 32 | + } |
| 33 | + #result { |
| 34 | + margin-top: 20px; |
| 35 | + padding: 15px; |
| 36 | + background: #e8f4fd; |
| 37 | + border-radius: 5px; |
| 38 | + white-space: pre-wrap; |
| 39 | + } |
| 40 | + </style> |
| 41 | +</head> |
| 42 | +<body> |
| 43 | + <h1>pangu.js Browser Example</h1> |
| 44 | + |
| 45 | + <div style="background: #fff3cd; border: 1px solid #ffeaa7; padding: 15px; margin-bottom: 20px; border-radius: 5px;"> |
| 46 | + <strong>Note:</strong> To run this example with ES modules support, start the web server: |
| 47 | + <pre style="background: #f8f9fa; padding: 10px; margin: 10px 0; border-radius: 3px;">npm run server</pre> |
| 48 | + Then open <a href="http://localhost:8080">http://localhost:8080</a> in your browser. |
| 49 | + </div> |
| 50 | + |
| 51 | + <div class="example"> |
| 52 | + <h2>UMD Version (Script Tag)</h2> |
| 53 | + <p id="demo1">測試文字:當你凝視著bug,bug也凝視著你</p> |
| 54 | + <button onclick="spacingDemo1()">Run</button> |
| 55 | + </div> |
| 56 | + |
| 57 | + <div class="example"> |
| 58 | + <h2>ESM Version (ES Modules)</h2> |
| 59 | + <p id="demo2">另一個測試:使用JavaScript開發Web應用程式</p> |
| 60 | + <button id="esmButton">Run</button> |
| 61 | + </div> |
| 62 | + |
| 63 | + <div class="example"> |
| 64 | + <h2>Auto-spacing Entire Page</h2> |
| 65 | + <p>這段文字包含English和中文mixed在一起,還有numbers123。</p> |
| 66 | + <p>pangu.js會自動在CJK字元和half-width characters之間加入空白。</p> |
| 67 | + <button onclick="autoSpacingPage()">Run</button> |
| 68 | + </div> |
| 69 | + |
| 70 | + <div id="result"></div> |
| 71 | + |
| 72 | + <!-- UMD Version --> |
| 73 | + <script src="node_modules/pangu/dist/browser/pangu.umd.js"></script> |
| 74 | + <script> |
| 75 | + function spacingDemo1() { |
| 76 | + const elem = document.getElementById('demo1'); |
| 77 | + const original = elem.textContent; |
| 78 | + pangu.spacingElementById('demo1'); |
| 79 | + const result = document.getElementById('result'); |
| 80 | + result.textContent = `UMD Version Result:\nOriginal: ${original}\nProcessed: ${elem.textContent}`; |
| 81 | + } |
| 82 | + |
| 83 | + function autoSpacingPage() { |
| 84 | + pangu.autoSpacingPage(); |
| 85 | + document.getElementById('result').textContent = 'Auto-spacing enabled! Try editing the text on the page.'; |
| 86 | + } |
| 87 | + </script> |
| 88 | + |
| 89 | + <!-- ESM Version --> |
| 90 | + <script type="module"> |
| 91 | + import { pangu } from './node_modules/pangu/dist/browser/pangu.js'; |
| 92 | + |
| 93 | + document.getElementById('esmButton').addEventListener('click', () => { |
| 94 | + const elem = document.getElementById('demo2'); |
| 95 | + const original = elem.textContent; |
| 96 | + const spaced = pangu.spacingText(original); |
| 97 | + elem.textContent = spaced; |
| 98 | + |
| 99 | + const result = document.getElementById('result'); |
| 100 | + result.textContent = `ESM Version Result:\nOriginal: ${original}\nProcessed: ${spaced}`; |
| 101 | + }); |
| 102 | + </script> |
| 103 | +</body> |
| 104 | +</html> |
0 commit comments