1- import { isNone , isNumber , isString } from "../../is.ts " ;
2- import { ensureArray } from "../../ensure.ts " ;
1+ import { isNumber , isString , isUndefined } from "@core/unknownutil " ;
2+ import { ensure , isArray } from "@core/unknownutil " ;
33import { getCachedLines } from "./getCachedLines.ts" ;
44import { takeInternalLines } from "./takeInternalLines.ts" ;
5- import type { BaseLine , Line } from "../../deps/scrapbox.ts " ;
5+ import type { BaseLine , Line } from "@cosense/types/userscript " ;
66import { lines } from "./dom.ts" ;
77import * as Text from "../../text.ts" ;
88
@@ -15,7 +15,7 @@ import * as Text from "../../text.ts";
1515export const getLineId = < T extends HTMLElement > (
1616 value ?: number | string | T ,
1717) : string | undefined => {
18- if ( isNone ( value ) ) return undefined ;
18+ if ( isUndefined ( value ) ) return undefined ;
1919
2020 // 行番号のとき
2121 if ( isNumber ( value ) ) return getBaseLine ( value ) ?. id ;
@@ -40,7 +40,7 @@ export const getLineId = <T extends HTMLElement>(
4040export const getLineNo = < T extends HTMLElement > (
4141 value ?: number | string | T ,
4242) : number | undefined => {
43- if ( isNone ( value ) ) return undefined ;
43+ if ( isUndefined ( value ) ) return undefined ;
4444
4545 // 行番号のとき
4646 if ( isNumber ( value ) ) return value ;
@@ -52,7 +52,7 @@ export const getLineNo = <T extends HTMLElement>(
5252export const getLine = < T extends HTMLElement > (
5353 value ?: number | string | T ,
5454) : Line | undefined => {
55- if ( isNone ( value ) ) return undefined ;
55+ if ( isUndefined ( value ) ) return undefined ;
5656
5757 // 行番号のとき
5858 if ( isNumber ( value ) ) return getLines ( ) [ value ] ;
@@ -64,7 +64,7 @@ export const getLine = <T extends HTMLElement>(
6464export const getBaseLine = < T extends HTMLElement > (
6565 value ?: number | string | T ,
6666) : BaseLine | undefined => {
67- if ( isNone ( value ) ) return undefined ;
67+ if ( isUndefined ( value ) ) return undefined ;
6868
6969 // 行番号のとき
7070 if ( isNumber ( value ) ) return takeInternalLines ( ) [ value ] ;
@@ -79,9 +79,9 @@ export const getLineDOM = <T extends HTMLElement>(
7979 if ( isLineDOM ( value ) ) return value ;
8080
8181 const id = getLineId ( value ) ;
82- if ( isNone ( id ) ) return id ;
82+ if ( isUndefined ( id ) ) return id ;
8383 const line = document . getElementById ( `L${ id } ` ) ;
84- if ( isNone ( line ) ) return undefined ;
84+ if ( isUndefined ( line ) ) return undefined ;
8585 return line as HTMLDivElement ;
8686} ;
8787export const isLineDOM = ( dom : unknown ) : dom is HTMLDivElement =>
@@ -90,15 +90,14 @@ export const isLineDOM = (dom: unknown): dom is HTMLDivElement =>
9090export const getLineCount = ( ) : number => takeInternalLines ( ) . length ;
9191
9292export const getLines = ( ) : readonly Line [ ] => {
93- const lines = getCachedLines ( ) ;
94- ensureArray < Line > ( lines , "scrapbox.Page.lines" ) ;
95- return lines ;
93+ const lines = ensure ( getCachedLines ( ) , isArray ) ;
94+ return lines as Line [ ] ;
9695} ;
9796
9897export const getText = < T extends HTMLElement > (
9998 value ?: number | string | T ,
10099) : string | undefined => {
101- if ( isNone ( value ) ) return undefined ;
100+ if ( isUndefined ( value ) ) return undefined ;
102101
103102 // 数字と文字列は行として扱う
104103 if ( isNumber ( value ) || isString ( value ) ) return getBaseLine ( value ) ?. text ;
@@ -118,7 +117,7 @@ export const getText = <T extends HTMLElement>(
118117 //中に含まれている文字の列番号を全て取得し、それに対応する文字列を返す
119118 const chars = [ ] as number [ ] ;
120119 const line = getBaseLine ( value ) ;
121- if ( isNone ( line ) ) return ;
120+ if ( isUndefined ( line ) ) return ;
122121 for ( const dom of getChars ( value ) ) {
123122 chars . push ( getIndex ( dom ) ) ;
124123 }
@@ -127,30 +126,30 @@ export const getText = <T extends HTMLElement>(
127126
128127export const getExternalLink = ( dom : HTMLElement ) : HTMLElement | undefined => {
129128 const link = dom . closest ( ".link" ) ;
130- if ( isNone ( link ) ) return undefined ;
129+ if ( isUndefined ( link ) ) return undefined ;
131130 return link as HTMLElement ;
132131} ;
133132export const getInternalLink = ( dom : HTMLElement ) : HTMLElement | undefined => {
134133 const link = dom . closest ( ".page-link" ) ;
135- if ( isNone ( link ) ) return undefined ;
134+ if ( isUndefined ( link ) ) return undefined ;
136135 return link as HTMLElement ;
137136} ;
138137export const getLink = ( dom : HTMLElement ) : HTMLElement | undefined => {
139138 const link = dom . closest ( ".link, .page-link" ) ;
140- if ( isNone ( link ) ) return undefined ;
139+ if ( isUndefined ( link ) ) return undefined ;
141140 return link as HTMLElement ;
142141} ;
143142
144143export const getFormula = ( dom : HTMLElement ) : HTMLElement | undefined => {
145144 const formula = dom . closest ( ".formula" ) ;
146- if ( isNone ( formula ) ) return undefined ;
145+ if ( isUndefined ( formula ) ) return undefined ;
147146 return formula as HTMLElement ;
148147} ;
149148export const getNextLine = < T extends HTMLElement > (
150149 value ?: number | string | T ,
151150) : Line | undefined => {
152151 const index = getLineNo ( value ) ;
153- if ( isNone ( index ) ) return undefined ;
152+ if ( isUndefined ( index ) ) return undefined ;
154153
155154 return getLine ( index + 1 ) ;
156155} ;
@@ -159,26 +158,26 @@ export const getPrevLine = <T extends HTMLElement>(
159158 value ?: number | string | T ,
160159) : Line | undefined => {
161160 const index = getLineNo ( value ) ;
162- if ( isNone ( index ) ) return undefined ;
161+ if ( isUndefined ( index ) ) return undefined ;
163162
164163 return getLine ( index - 1 ) ;
165164} ;
166165
167166export const getHeadLineDOM = ( ) : HTMLDivElement | undefined => {
168167 const line = lines ( ) ?. firstElementChild ;
169- if ( isNone ( line ) ) return undefined ;
168+ if ( isUndefined ( line ) ) return undefined ;
170169 return line as HTMLDivElement ;
171170} ;
172171export const getTailLineDOM = ( ) : HTMLDivElement | undefined => {
173172 const line = lines ( ) ?. lastElementChild ;
174- if ( isNone ( line ) ) return undefined ;
173+ if ( isUndefined ( line ) ) return undefined ;
175174 return line as HTMLDivElement ;
176175} ;
177176export const getIndentCount = < T extends HTMLElement > (
178177 value ?: number | string | T ,
179178) : number | undefined => {
180179 const text = getText ( value ) ;
181- if ( isNone ( text ) ) return undefined ;
180+ if ( isUndefined ( text ) ) return undefined ;
182181 return Text . getIndentCount ( text ) ;
183182} ;
184183/** 指定した行の配下にある行の数を返す
@@ -189,7 +188,7 @@ export const getIndentLineCount = <T extends HTMLElement>(
189188 value ?: number | string | T ,
190189) : number | undefined => {
191190 const index = getLineNo ( value ) ;
192- if ( isNone ( index ) ) return ;
191+ if ( isUndefined ( index ) ) return ;
193192 return Text . getIndentLineCount ( index , getLines ( ) ) ;
194193} ;
195194
@@ -210,7 +209,7 @@ export const getIndex = (dom: HTMLSpanElement): number => {
210209 if ( ! isCharDOM ( dom ) ) throw Error ( "A char DOM is required." ) ;
211210
212211 const index = dom . className . match ( / c - ( \d + ) / ) ?. [ 1 ] ;
213- if ( isNone ( index ) ) throw Error ( '.char-index must have ".c-{\\d}"' ) ;
212+ if ( isUndefined ( index ) ) throw Error ( '.char-index must have ".c-{\\d}"' ) ;
214213 return parseInt ( index ) ;
215214} ;
216215export const getHeadCharDOM = (
@@ -242,7 +241,7 @@ export const getDOMFromPoint = (
242241 const char = targets . find ( ( target ) => isCharDOM ( target ) ) ;
243242 const line = targets . find ( ( target ) => isLineDOM ( target ) ) ;
244243 return {
245- char : isNone ( char ) ? undefined : char as HTMLSpanElement ,
246- line : isNone ( line ) ? undefined : line as HTMLDivElement ,
244+ char : isUndefined ( char ) ? undefined : char as HTMLSpanElement ,
245+ line : isUndefined ( line ) ? undefined : line as HTMLDivElement ,
247246 } ;
248247} ;
0 commit comments