aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
-rw-r--r--src/dumbyUtils.mjs8
-rw-r--r--src/utils.mjs17
2 files changed, 22 insertions, 3 deletions
diff --git a/src/dumbyUtils.mjs b/src/dumbyUtils.mjs
index 12b5905..2f64e38 100644
--- a/src/dumbyUtils.mjs
+++ b/src/dumbyUtils.mjs
@@ -1,5 +1,5 @@
1import LeaderLine from 'leader-line' 1import LeaderLine from 'leader-line'
2import { insideWindow, insideParent, replaceTextNodes } from './utils' 2import { insideWindow, insideParent, replaceTextNodes, full2Half } from './utils'
3import proj4 from 'proj4' 3import proj4 from 'proj4'
4 4
5export const coordPattern = /^geo:([-]?[0-9.]+),([-]?[0-9.]+)/ 5export const coordPattern = /^geo:([-]?[0-9.]+),([-]?[0-9.]+)/
@@ -439,11 +439,13 @@ export const dragForAnchor = (container, range, endOfLeaderLine) => {
439} 439}
440 440
441export const addGeoSchemeByText = async (node) => { 441export const addGeoSchemeByText = async (node) => {
442 const coordPatterns = /(-?\d+\.?\d*)([,\x2F\uFF0C])(-?\d+\.?\d*)/ 442 const digit = '[\\d\\uFF10-\\uFF19]'
443 const decimal = '[.\\uFF0E]'
444 const coordPatterns = `(-?${digit}+${decimal}?${digit}*)([,\x2F\uFF0C])(-?${digit}+${decimal}?${digit}*)`
443 const re = new RegExp(coordPatterns, 'g') 445 const re = new RegExp(coordPatterns, 'g')
444 446
445 return replaceTextNodes(node, re, match => { 447 return replaceTextNodes(node, re, match => {
446 const [x, y] = [match.at(1), match.at(3)] 448 const [x, y] = [full2Half(match.at(1)), full2Half(match.at(3))]
447 // Don't process string which can be used as date 449 // Don't process string which can be used as date
448 if (Date.parse(match.at(0) + ' 1990')) return null 450 if (Date.parse(match.at(0) + ' 1990')) return null
449 451
diff --git a/src/utils.mjs b/src/utils.mjs
index dbb3881..d2c5d8f 100644
--- a/src/utils.mjs
+++ b/src/utils.mjs
@@ -235,3 +235,20 @@ export function getCommonAncestor (selector) {
235 // Return the common ancestor 235 // Return the common ancestor
236 return range.commonAncestorContainer 236 return range.commonAncestorContainer
237} 237}
238
239/**
240 * full2Half: full-Width Digits To Half-Width.
241 *
242 * @param {String} str
243 */
244export const full2Half = (str) => {
245 // Create a regular expression to match full-width digits (U+FF10 to U+FF19)
246 const fullWidthDigitsRegex = /[\uFF0E\uFF10-\uFF19]/g
247
248 // Replace full-width digits with their half-width equivalents
249 return str.replace(fullWidthDigitsRegex, (match) => {
250 const fullWidthDigit = match.charCodeAt(0)
251 const halfWidthDigit = fullWidthDigit - 65248 // Offset to convert full-width to half-width
252 return String.fromCharCode(halfWidthDigit)
253 })
254}