codelight.js 1.0.0 → 1.1.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGES.md +9 -0
- package/README.md +9 -0
- package/build/codelight.js +1 -1
- package/build/codelight.min.js +1 -1
- package/es/{chunk-CNPC3G6S.js → chunk-ZYEPC5GO.js} +1 -1
- package/es/codelight.js +2 -2
- package/es/react.js +2 -2
- package/lib/{chunk-HXH3J6GU.cjs → chunk-KY23A6M5.cjs} +1 -1
- package/lib/codelight.cjs +15 -15
- package/lib/react.cjs +4 -4
- package/package.json +7 -3
package/CHANGES.md
CHANGED
package/README.md
CHANGED
|
@@ -1,3 +1,12 @@
|
|
|
1
|
+
<p align="center">
|
|
2
|
+
<a href="https://codelightjs.github.io/">
|
|
3
|
+
<picture>
|
|
4
|
+
<source media="(prefers-color-scheme: dark)" srcset="https://raw.githubusercontent.com/codelightjs/codelight.js/main/assets/logo-dark.svg">
|
|
5
|
+
<img src="https://raw.githubusercontent.com/codelightjs/codelight.js/main/assets/logo.svg" alt="codelight.js" width="330">
|
|
6
|
+
</picture>
|
|
7
|
+
</a>
|
|
8
|
+
</p>
|
|
9
|
+
|
|
1
10
|
# codelight.js
|
|
2
11
|
|
|
3
12
|
**Syntax highlighting for code that streams in, like AI chat replies.** Each line is highlighted once, when it's finished. Only the line still being written is redrawn, so long answers don't flicker, don't slow down, and text stays selectable while the reply arrives. It works for code that's already on the page, too.
|
package/build/codelight.js
CHANGED
package/build/codelight.min.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
/*! codelight.js 1.
|
|
1
|
+
/*! codelight.js 1.1.1 | MIT License | https://github.com/codelightjs/codelight.js */
|
|
2
2
|
"use strict";var codelight=(()=>{var z=Object.defineProperty;var ze=Object.getOwnPropertyDescriptor;var Re=Object.getOwnPropertyNames;var Me=Object.prototype.hasOwnProperty;var qe=(t,e,o)=>e in t?z(t,e,{enumerable:!0,configurable:!0,writable:!0,value:o}):t[e]=o;var De=(t,e)=>{for(var o in e)z(t,o,{get:e[o],enumerable:!0})},$e=(t,e,o,a)=>{if(e&&typeof e=="object"||typeof e=="function")for(let r of Re(e))!Me.call(t,r)&&r!==o&&z(t,r,{get:()=>e[r],enumerable:!(a=ze(e,r))||a.enumerable});return t};var Ue=t=>$e(z({},"__esModule",{value:!0}),t);var re=(t,e,o)=>qe(t,typeof e!="symbol"?e+"":e,o);var rt={};De(rt,{createMarkup:()=>T,createStream:()=>N,default:()=>nt,defineLanguage:()=>c,escapeHtml:()=>O,getLanguage:()=>A,highlight:()=>j,highlightAll:()=>K,highlightElement:()=>Z,injectTheme:()=>ee,listLanguages:()=>J,mount:()=>X,registerLanguage:()=>H,renderLine:()=>L,splitFences:()=>V,themeCss:()=>W,tokenize:()=>U});var _=class{constructor(){re(this,"tokens",[])}add(e,o){if(!o)return;let a=this.tokens[this.tokens.length-1];a&&a.type===e?a.text+=o:this.tokens.push(e?{type:e,text:o}:{text:o})}},C=(t,e)=>new Set((t??"").split(/\s+/).filter(Boolean).map(o=>e?o.toLowerCase():o)),ae=t=>new RegExp(t.source,t.flags.replace(/[gy]/g,"")+"y"),oe=/(?:0[xX][\da-fA-F_]+|0[bB][01_]+|0[oO][0-7_]+|(?:\d[\d_]*(?:\.\d[\d_]*)?|\.\d[\d_]*)(?:[eE][+-]?\d+)?)\w*/y,Ze=/[A-Za-z_$][\w$]*/,se=/\s+/y,ie=/[+\-*/%=<>!&|^~?:]+/y,ce=/\s*\(/y,We="()[]{},;.";function le(t,e,o,a){for(let r=e;r<t.length;r++){if(a&&t[r]==="\\"){r++;continue}if(t.startsWith(o,r))return r+o.length}return-1}function c(t){let e=t.caseInsensitive??!1,o=C(t.keywords,e),a=C(t.constants,e),r=C(t.types,e),n=C(t.variables,e),l=C(t.builtins,e),s=(t.rules??[]).map(i=>({match:ae(i.match),type:i.type})),m=[...t.strings??[]].sort((i,w)=>w.open.length-i.open.length),u=ae(t.identifier??Ze),x=t.calls??!0;function v(i,w,f){let d=e?i.toLowerCase():i;if(o.has(d))return"keyword";if(a.has(d))return"constant";if(r.has(d))return"type";if(n.has(d))return"variable";if(l.has(d)||x&&(ce.lastIndex=f,ce.test(w)))return"function";if(t.classNames&&/^[A-Z]/.test(i)&&/[a-z]/.test(i))return"type"}return{tokenizeLine(i,w){let f=new _,d=w,p=0;if(d){let g=le(i,0,d.close,d.escape);if(g<0)return f.add(d.type,i),{tokens:f.tokens,state:d};f.add(d.type,i.slice(0,g)),p=g,d=null}e:for(;p<i.length;){for(let y of s){y.match.lastIndex=p;let k=y.match.exec(i);if(k&&k[0]){f.add(y.type,k[0]),p+=k[0].length;continue e}}for(let[y,k]of t.blockComment??[]){if(!i.startsWith(y,p))continue;let S=i.indexOf(k,p+y.length);if(S<0){f.add("comment",i.slice(p)),d={close:k,type:"comment",escape:!1};break e}f.add("comment",i.slice(p,S+k.length)),p=S+k.length;continue e}for(let y of t.lineComment??[])if(i.startsWith(y,p)){f.add("comment",i.slice(p));break e}for(let y of m){if(!i.startsWith(y.open,p))continue;let k=y.type??"string",S=y.close??y.open,ne=y.escape??!0,I=le(i,p+y.open.length,S,ne);if(I<0){f.add(k,i.slice(p)),y.multiline&&(d={close:S,type:k,escape:ne});break e}f.add(k,i.slice(p,I)),p=I;continue e}let g;if(oe.lastIndex=p,g=oe.exec(i)){f.add("number",g[0]),p+=g[0].length;continue}if(u.lastIndex=p,(g=u.exec(i))&&g[0]){f.add(v(g[0],i,p+g[0].length),g[0]),p+=g[0].length;continue}if(se.lastIndex=p,g=se.exec(i)){f.add(void 0,g[0]),p+=g[0].length;continue}if(ie.lastIndex=p,g=ie.exec(i)){f.add("operator",g[0]),p+=g[0].length;continue}let te=i[p];f.add(We.includes(te)?"punctuation":void 0,te),p++}return{tokens:f.tokens,state:d}}}}var R={tokenizeLine:t=>({tokens:t?[{text:t}]:[],state:null})};var pe=c({strings:[{open:'"',multiline:!0},{open:"'",escape:!1,multiline:!0}],keywords:"if then else elif fi for while until do done case esac in function select return exit break continue local export readonly declare unset source alias time",builtins:"echo cd printf read set shift test eval exec trap pwd ls cat grep sed awk find mkdir rm cp mv chmod chown touch curl wget tar sudo git npm npx pnpm yarn bun node deno python python3 pip pip3 docker kubectl ssh make brew apt apt-get",rules:[{match:/(?<=^|\s)#.*/,type:"comment"},{match:/\$(?:\{[^}]*\}|[A-Za-z_]\w*|[\d@#?$!*-])/,type:"variable"},{match:/(?<=^\s*(?:(?:export|local|declare|readonly)\s+)?)[A-Za-z_]\w*(?==)/,type:"variable"},{match:/(?<=\s)--?[A-Za-z][\w-]*/,type:"attr"}],identifier:/[A-Za-z_][\w-]*/,calls:!1});var h={lineComment:["//"],blockComment:[["/*","*/"]]},b=[{open:'"'},{open:"'"}];var P="auto break case const continue default do else enum extern for goto if inline register restrict return sizeof static struct switch typedef union volatile while",F="char double float int long short signed unsigned void bool size_t ssize_t int8_t int16_t int32_t int64_t uint8_t uint16_t uint32_t uint64_t FILE",Q=[{match:/(?<=^\s*#\s*include\s*)<[^>]*>/,type:"string"},{match:/(?<=^\s*)#\s*[A-Za-z]+/,type:"meta"}],ue=c({...h,strings:b,keywords:P,types:F,constants:"NULL true false",rules:Q});var fe=c({...h,strings:b,keywords:P+" class namespace template typename public private protected virtual override final new delete this try catch throw using operator friend explicit constexpr consteval noexcept auto decltype static_cast dynamic_cast reinterpret_cast const_cast co_await co_return co_yield concept requires mutable",types:F+" string vector map unordered_map set array unique_ptr shared_ptr optional",constants:"nullptr NULL true false",rules:Q,classNames:!0});var me=c({...h,strings:[{open:'@"',close:'"',escape:!1,multiline:!0},{open:'$"',close:'"'},...b],keywords:"abstract as base break case catch checked class const continue default delegate do else enum event explicit extern finally fixed for foreach goto if implicit in interface internal is lock namespace new operator out override params private protected public readonly ref return sealed sizeof stackalloc static struct switch this throw try typeof unchecked unsafe using virtual volatile while async await var record get set init yield where when",types:"bool byte char decimal double float int long object sbyte short string uint ulong ushort void dynamic",constants:"true false null",classNames:!0});var M=c({blockComment:[["/*","*/"]],strings:b,rules:[{match:/@[\w-]+/,type:"keyword"},{match:/#[\da-fA-F]{3,8}(?![\w-])/,type:"number"},{match:/(?:--|-?[A-Za-z])[\w-]*(?=\s*:(?!:)[^{};]*(?:[;})]|$))/,type:"property"},{match:/[.#][A-Za-z_-][\w-]*/,type:"type"},{match:/::?[A-Za-z-]+/,type:"attr"},{match:/!\s*important/,type:"keyword"}],identifier:/-?[A-Za-z_][\w-]*/});var Ie={tokenizeLine(t){if(!t)return{tokens:[],state:null};let e=t.startsWith("+++")||t.startsWith("---")||t.startsWith("@@")||t.startsWith("diff ")||t.startsWith("index ")?"meta":t[0]==="+"?"inserted":t[0]==="-"?"deleted":void 0;return{tokens:[e?{type:e,text:t}:{text:t}],state:null}}},de=Ie;var ge=c({...h,strings:[{open:'"'},{open:"'"},{open:"`",escape:!1,multiline:!0}],keywords:"break case chan const continue default defer else fallthrough for func go goto if import interface map package range return select struct switch type var",constants:"true false nil iota",types:"string int int8 int16 int32 int64 uint uint8 uint16 uint32 uint64 uintptr float32 float64 complex64 complex128 bool byte rune error any",builtins:"append cap close copy delete len make new panic print println recover"});var he=c({...h,strings:[{open:'"""',multiline:!0},...b],keywords:"abstract assert break case catch class const continue default do else enum extends final finally for goto if implements import instanceof interface native new package private protected public return static strictfp super switch synchronized this throw throws transient try volatile while var record sealed permits yield",types:"boolean byte char double float int long short void",constants:"true false null",rules:[{match:/@[A-Za-z_]\w*/,type:"meta"}],classNames:!0});var Y="break case catch class const continue debugger default delete do else export extends finally for function if import in instanceof let new return super switch this throw try typeof var void while with yield async await of static get set from as",G="true false null undefined NaN Infinity",B={match:/(?<=(?:^|[(=?:,&|{}[>;]|\breturn)\s*)<\/?[A-Za-z][\w.:-]*(?=[\s/>]|$)/,type:"tag"},q={match:/@[A-Za-z_$][\w$.]*/,type:"meta"},D=c({...h,strings:[...b,{open:"`",multiline:!0}],keywords:Y,constants:G,rules:[B,q],classNames:!0});var ye=c({...h,strings:[{open:'"'}],constants:"true false null",rules:[{match:/"(?:[^"\\]|\\.)*"(?=\s*:)/,type:"property"}],calls:!1});var be=c({lineComment:["//","#"],blockComment:[["/*","*/"]],strings:[{open:'"',multiline:!0},{open:"'",multiline:!0}],keywords:"abstract and array as break callable case catch class clone const continue declare default do echo else elseif empty enddeclare endfor endforeach endif endswitch endwhile enum extends final finally fn for foreach function global goto if implements include include_once instanceof insteadof interface isset list match namespace new or print private protected public readonly require require_once return static switch throw trait try unset use var while xor yield",constants:"true false null TRUE FALSE NULL",types:"int float string bool void mixed never object iterable",rules:[{match:/<\?(?:php|=)?|\?>/,type:"meta"},{match:/\$[A-Za-z_]\w*/,type:"variable"}],classNames:!0});var xe=c({lineComment:["#"],strings:[{open:'"""',multiline:!0},{open:"'''",multiline:!0},...b],keywords:"and as assert async await break class continue def del elif else except finally for from global if import in is lambda nonlocal not or pass raise return try while with yield match case",constants:"True False None",variables:"self cls",types:"int float str bool list dict set tuple bytes object Exception",rules:[{match:/(?<=^\s*)@[\w.]+/,type:"meta"},{match:/[rRbBuUfF]{1,2}(?=["'])/,type:"string"}],classNames:!0});var we=c({lineComment:["#"],strings:[{open:'"',multiline:!0},{open:"'",multiline:!0}],keywords:"alias and begin break case class def defined? do else elsif end ensure for if in module next not or redo rescue retry return self super then undef unless until when while yield require require_relative include extend attr_accessor attr_reader attr_writer private protected public lambda proc",builtins:"puts print p raise",constants:"true false nil",rules:[{match:/@{1,2}[A-Za-z_]\w*|\$[A-Za-z_]\w*/,type:"variable"},{match:/(?<![:\w]):[A-Za-z_]\w*[?!]?/,type:"constant"}],identifier:/[A-Za-z_]\w*[?!]?/,classNames:!0});var ke=c({...h,strings:[{open:'"',multiline:!0},{open:"'"}],keywords:"as async await break const continue crate dyn else enum extern fn for if impl in let loop match mod move mut pub ref return self Self static struct super trait type unsafe use where while",constants:"true false None",types:"i8 i16 i32 i64 i128 isize u8 u16 u32 u64 u128 usize f32 f64 bool char str",rules:[{match:/#!?\[[^\]]*\]/,type:"meta"},{match:/'[A-Za-z_]\w*(?!')/,type:"keyword"},{match:/[A-Za-z_]\w*!(?=\s*[([{])/,type:"function"}],classNames:!0});var ve=c({lineComment:["--"],blockComment:[["/*","*/"]],strings:[{open:"'",escape:!1},{open:'"',escape:!1,type:"property"},{open:"`",escape:!1,type:"property"}],keywords:"select from where and or not insert into values update set delete create table alter drop index primary key foreign references join left right inner outer full cross on as group by order having limit offset union all distinct case when then else end is in like ilike between exists default constraint unique check view begin commit rollback transaction returning with recursive if desc asc add column grant revoke cascade truncate database schema explain using natural over partition window",constants:"null true false",types:"int integer bigint smallint serial bigserial varchar char text boolean bool date time timestamp timestamptz interval decimal numeric float real double precision uuid json jsonb blob bytea",caseInsensitive:!0});var Pe=" interface type enum implements namespace declare abstract readonly private protected public keyof infer is satisfies asserts module override unique",Le=t=>({...h,strings:[...b,{open:"`",multiline:!0}],keywords:Y+Pe,types:"string number boolean any unknown never void object symbol bigint",constants:G,rules:t?[B,q]:[q],classNames:!0}),Se=c(Le(!1)),Ee=c(Le(!0));var Fe=/<(\/?)([A-Za-z][\w:.-]*)/y,Qe=/&(?:#\d+|#[xX][\da-fA-F]+|\w+);/y,Ye=/[^<&]+/y,Ge=/[^\s=/>"']+/y,Be=/[^\s>"']+/y,He=/\s+/y,E=(t,e,o)=>(t.lastIndex=o,t.exec(e));function T(t={}){return{tokenizeLine(e,o){let a=new _,r=o,n=0,l;for(;n<e.length;){if(!r){if(e.startsWith("<!--",n)){let s=e.indexOf("-->",n+4);if(s<0){a.add("comment",e.slice(n)),r={m:"comment"};break}a.add("comment",e.slice(n,s+3)),n=s+3}else if(e.startsWith("<!",n)||e.startsWith("<?",n)){let s=e.indexOf(">",n);if(s<0){a.add("meta",e.slice(n)),r={m:"meta"};break}a.add("meta",e.slice(n,s+1)),n=s+1}else(l=E(Fe,e,n))?(a.add("punctuation",l[1]?"</":"<"),a.add("tag",l[2]),r={m:"tag",name:l[2].toLowerCase(),closing:!!l[1]},n+=l[0].length):(l=E(Qe,e,n))?(a.add("constant",l[0]),n+=l[0].length):(l=E(Ye,e,n))?(a.add(void 0,l[0]),n+=l[0].length):(a.add(void 0,e[n]),n++);continue}if(r.m==="comment"||r.m==="meta"){let s=r.m==="comment"?"-->":">",m=r.m==="comment"?"comment":"meta",u=e.indexOf(s,n);if(u<0){a.add(m,e.slice(n));break}a.add(m,e.slice(n,u+s.length)),n=u+s.length,r=null;continue}if(r.m==="embed"){let s=e.toLowerCase().indexOf(r.end,n),m=s<0?e.slice(n):e.slice(n,s),u=r.lang.tokenizeLine(m,r.inner);for(let x of u.tokens)a.add(x.type,x.text);if(s<0){r={...r,inner:u.state};break}r=null,n=s;continue}if(r.quote){let s=e.indexOf(r.quote,n);if(s<0){a.add("string",e.slice(n));break}a.add("string",e.slice(n,s+1)),n=s+1,r={...r,quote:void 0,eq:!1}}else if(l=E(He,e,n))a.add(void 0,l[0]),n+=l[0].length;else if(e.startsWith("/>",n)||e[n]===">"){let s=e[n]===">"?1:2;a.add("punctuation",e.slice(n,n+s)),n+=s;let m=s===1&&!r.closing?t[r.name]:void 0;r=m?{m:"embed",end:`</${r.name}`,lang:m,inner:null}:null}else if(e[n]==="=")a.add("operator","="),n++,r={...r,eq:!0};else if(e[n]==='"'||e[n]==="'"){let s=e[n],m=e.indexOf(s,n+1);if(m<0){a.add("string",e.slice(n)),r={...r,quote:s};break}a.add("string",e.slice(n,m+1)),n=m+1,r={...r,eq:!1}}else r.eq&&(l=E(Be,e,n))?(a.add("string",l[0]),n+=l[0].length,r={...r,eq:!1}):(l=E(Ge,e,n))?(a.add("attr",l[0]),n+=l[0].length):(a.add(void 0,e[n]),n++)}return{tokens:a.tokens,state:r}}}}var Ce=T({script:D,style:M});var _e=c({strings:[{open:'"'},{open:"'",escape:!1}],constants:"true false null yes no on off ~",caseInsensitive:!0,rules:[{match:/(?<=^|\s)#.*/,type:"comment"},{match:/^(?:---|\.\.\.)(?=\s*$)/,type:"meta"},{match:/[^\s#:'"[\]{},-][^#:]*?(?=:(?:\s|$))|(?<=^\s*-\s+)[^\s#:'"[\]{},][^#:]*?(?=:(?:\s|$))/,type:"property"},{match:/[&*][\w-]+/,type:"variable"},{match:/!!?[\w-]+/,type:"type"}],identifier:/[A-Za-z_][\w-]*/,calls:!1});var Te={javascript:D,typescript:Se,tsx:Ee,json:ye,python:xe,bash:pe,ruby:we,php:be,go:ge,rust:ke,java:he,c:ue,cpp:fe,csharp:me,sql:ve,css:M,yaml:_e,xml:Ce,diff:de,plaintext:R};var $=new Map(Object.entries(Te)),Ae=new Map(Object.entries({js:"javascript",jsx:"javascript",mjs:"javascript",cjs:"javascript",node:"javascript",ts:"typescript",mts:"typescript",cts:"typescript",jsonc:"json",json5:"json",py:"python",python3:"python",sh:"bash",shell:"bash",zsh:"bash",shellscript:"bash",console:"bash",terminal:"bash",rb:"ruby",golang:"go",rs:"rust",h:"c","c++":"cpp",cc:"cpp",cxx:"cpp",hpp:"cpp",cs:"csharp","c#":"csharp",postgres:"sql",postgresql:"sql",mysql:"sql",sqlite:"sql",plsql:"sql",scss:"css",less:"css",yml:"yaml",html:"xml",xhtml:"xml",svg:"xml",vue:"xml",svelte:"xml",patch:"diff",text:"plaintext",txt:"plaintext",plain:"plaintext","":"plaintext"}));function A(t){let e=(t??"").trim().toLowerCase();return $.get(e)??$.get(Ae.get(e)??"")}function H(t,e,o=[]){$.set(t.toLowerCase(),e);for(let a of o)Ae.set(a.toLowerCase(),t.toLowerCase())}function J(){return[...$.keys()]}var Oe=t=>typeof t=="object"?t:A(t)??R,Je={"&":"&","<":"<",">":">",'"':"""};function O(t){return t.replace(/[&<>"]/g,e=>Je[e])}function L(t){let e="";for(let o of t)e+=o.type?`<span class="cl-${o.type}">${O(o.text)}</span>`:O(o.text);return e}function U(t,e){let o=Oe(e),a=null;return t.split(`
|
|
3
3
|
`).map(r=>{let n=o.tokenizeLine(r.replace(/\r$/,""),a);return a=n.state,n.tokens})}function j(t,e){return U(t,e).map(L).join(`
|
|
4
4
|
`)}function N(t){let e=Oe(t),o=null,a="",r="";return{get text(){return r},push(n){r+=n,a+=n;let l=[],s;for(;(s=a.indexOf(`
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
/*! codelight.js 1.
|
|
1
|
+
/*! codelight.js 1.1.1 | MIT License | https://github.com/codelightjs/codelight.js */
|
|
2
2
|
var __defProp = Object.defineProperty;
|
|
3
3
|
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
4
4
|
var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
|
package/es/codelight.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
/*! codelight.js 1.
|
|
1
|
+
/*! codelight.js 1.1.1 | MIT License | https://github.com/codelightjs/codelight.js */
|
|
2
2
|
import {
|
|
3
3
|
createMarkup,
|
|
4
4
|
createStream,
|
|
@@ -11,7 +11,7 @@ import {
|
|
|
11
11
|
registerLanguage,
|
|
12
12
|
renderLine,
|
|
13
13
|
tokenize
|
|
14
|
-
} from "./chunk-
|
|
14
|
+
} from "./chunk-ZYEPC5GO.js";
|
|
15
15
|
|
|
16
16
|
// src/lib/auto.ts
|
|
17
17
|
var MARKDOWN_CLASS = /(?:^|\s)language-(\S+)/;
|
package/es/react.js
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
/*! codelight.js 1.
|
|
1
|
+
/*! codelight.js 1.1.1 | MIT License | https://github.com/codelightjs/codelight.js */
|
|
2
2
|
import {
|
|
3
3
|
highlight,
|
|
4
4
|
mount
|
|
5
|
-
} from "./chunk-
|
|
5
|
+
} from "./chunk-ZYEPC5GO.js";
|
|
6
6
|
|
|
7
7
|
// src/react.ts
|
|
8
8
|
import { createElement, useEffect, useLayoutEffect, useRef, useState } from "react";
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports, "__esModule", {value: true}); function _nullishCoalesce(lhs, rhsFn) { if (lhs != null) { return lhs; } else { return rhsFn(); } }/*! codelight.js 1.
|
|
1
|
+
"use strict";Object.defineProperty(exports, "__esModule", {value: true}); function _nullishCoalesce(lhs, rhsFn) { if (lhs != null) { return lhs; } else { return rhsFn(); } }/*! codelight.js 1.1.1 | MIT License | https://github.com/codelightjs/codelight.js */
|
|
2
2
|
var __defProp = Object.defineProperty;
|
|
3
3
|
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
4
4
|
var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
|
package/lib/codelight.cjs
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports, "__esModule", {value: true}); function _nullishCoalesce(lhs, rhsFn) { if (lhs != null) { return lhs; } else { return rhsFn(); } } function _optionalChain(ops) { let lastAccessLHS = undefined; let value = ops[0]; let i = 1; while (i < ops.length) { const op = ops[i]; const fn = ops[i + 1]; i += 2; if ((op === 'optionalAccess' || op === 'optionalCall') && value == null) { return undefined; } if (op === 'access' || op === 'optionalAccess') { lastAccessLHS = value; value = fn(value); } else if (op === 'call' || op === 'optionalCall') { value = fn((...args) => value.call(lastAccessLHS, ...args)); lastAccessLHS = undefined; } } return value; }/*! codelight.js 1.
|
|
1
|
+
"use strict";Object.defineProperty(exports, "__esModule", {value: true}); function _nullishCoalesce(lhs, rhsFn) { if (lhs != null) { return lhs; } else { return rhsFn(); } } function _optionalChain(ops) { let lastAccessLHS = undefined; let value = ops[0]; let i = 1; while (i < ops.length) { const op = ops[i]; const fn = ops[i + 1]; i += 2; if ((op === 'optionalAccess' || op === 'optionalCall') && value == null) { return undefined; } if (op === 'access' || op === 'optionalAccess') { lastAccessLHS = value; value = fn(value); } else if (op === 'call' || op === 'optionalCall') { value = fn((...args) => value.call(lastAccessLHS, ...args)); lastAccessLHS = undefined; } } return value; }/*! codelight.js 1.1.1 | MIT License | https://github.com/codelightjs/codelight.js */
|
|
2
2
|
|
|
3
3
|
|
|
4
4
|
|
|
@@ -11,7 +11,7 @@
|
|
|
11
11
|
|
|
12
12
|
|
|
13
13
|
|
|
14
|
-
var
|
|
14
|
+
var _chunkKY23A6M5cjs = require('./chunk-KY23A6M5.cjs');
|
|
15
15
|
|
|
16
16
|
// src/lib/auto.ts
|
|
17
17
|
var MARKDOWN_CLASS = /(?:^|\s)language-(\S+)/;
|
|
@@ -19,7 +19,7 @@ function languageOf(code) {
|
|
|
19
19
|
return _nullishCoalesce(_nullishCoalesce(_nullishCoalesce(code.getAttribute("data-lang"), () => ( _optionalChain([code, 'access', _ => _.parentElement, 'optionalAccess', _2 => _2.getAttribute, 'call', _3 => _3("data-lang")]))), () => ( _optionalChain([MARKDOWN_CLASS, 'access', _4 => _4.exec, 'call', _5 => _5(code.className), 'optionalAccess', _6 => _6[1]]))), () => ( ""));
|
|
20
20
|
}
|
|
21
21
|
function highlightElement(code, lang = languageOf(code)) {
|
|
22
|
-
code.innerHTML =
|
|
22
|
+
code.innerHTML = _chunkKY23A6M5cjs.highlight.call(void 0, _nullishCoalesce(code.textContent, () => ( "")), lang);
|
|
23
23
|
code.classList.add("cl");
|
|
24
24
|
code.setAttribute("data-cl", lang);
|
|
25
25
|
}
|
|
@@ -97,22 +97,22 @@ function injectTheme(doc = document) {
|
|
|
97
97
|
|
|
98
98
|
// src/codelight.ts
|
|
99
99
|
var codelight = {
|
|
100
|
-
createMarkup:
|
|
101
|
-
createStream:
|
|
102
|
-
defineLanguage:
|
|
103
|
-
escapeHtml:
|
|
104
|
-
getLanguage:
|
|
105
|
-
highlight:
|
|
100
|
+
createMarkup: _chunkKY23A6M5cjs.createMarkup,
|
|
101
|
+
createStream: _chunkKY23A6M5cjs.createStream,
|
|
102
|
+
defineLanguage: _chunkKY23A6M5cjs.defineLanguage,
|
|
103
|
+
escapeHtml: _chunkKY23A6M5cjs.escapeHtml,
|
|
104
|
+
getLanguage: _chunkKY23A6M5cjs.getLanguage,
|
|
105
|
+
highlight: _chunkKY23A6M5cjs.highlight,
|
|
106
106
|
highlightAll,
|
|
107
107
|
highlightElement,
|
|
108
108
|
injectTheme,
|
|
109
|
-
listLanguages:
|
|
110
|
-
mount:
|
|
111
|
-
registerLanguage:
|
|
112
|
-
renderLine:
|
|
109
|
+
listLanguages: _chunkKY23A6M5cjs.listLanguages,
|
|
110
|
+
mount: _chunkKY23A6M5cjs.mount,
|
|
111
|
+
registerLanguage: _chunkKY23A6M5cjs.registerLanguage,
|
|
112
|
+
renderLine: _chunkKY23A6M5cjs.renderLine,
|
|
113
113
|
splitFences,
|
|
114
114
|
themeCss,
|
|
115
|
-
tokenize:
|
|
115
|
+
tokenize: _chunkKY23A6M5cjs.tokenize
|
|
116
116
|
};
|
|
117
117
|
var codelight_default = codelight;
|
|
118
118
|
|
|
@@ -133,7 +133,7 @@ var codelight_default = codelight;
|
|
|
133
133
|
|
|
134
134
|
|
|
135
135
|
|
|
136
|
-
exports.createMarkup =
|
|
136
|
+
exports.createMarkup = _chunkKY23A6M5cjs.createMarkup; exports.createStream = _chunkKY23A6M5cjs.createStream; exports.default = codelight_default; exports.defineLanguage = _chunkKY23A6M5cjs.defineLanguage; exports.escapeHtml = _chunkKY23A6M5cjs.escapeHtml; exports.getLanguage = _chunkKY23A6M5cjs.getLanguage; exports.highlight = _chunkKY23A6M5cjs.highlight; exports.highlightAll = highlightAll; exports.highlightElement = highlightElement; exports.injectTheme = injectTheme; exports.listLanguages = _chunkKY23A6M5cjs.listLanguages; exports.mount = _chunkKY23A6M5cjs.mount; exports.registerLanguage = _chunkKY23A6M5cjs.registerLanguage; exports.renderLine = _chunkKY23A6M5cjs.renderLine; exports.splitFences = splitFences; exports.themeCss = themeCss; exports.tokenize = _chunkKY23A6M5cjs.tokenize;
|
|
137
137
|
/*!
|
|
138
138
|
codelight.js — syntax highlighting for code that streams in, like AI chat replies.
|
|
139
139
|
MIT License · https://github.com/codelightjs/codelight.js
|
package/lib/react.cjs
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports, "__esModule", {value: true}); function _optionalChain(ops) { let lastAccessLHS = undefined; let value = ops[0]; let i = 1; while (i < ops.length) { const op = ops[i]; const fn = ops[i + 1]; i += 2; if ((op === 'optionalAccess' || op === 'optionalCall') && value == null) { return undefined; } if (op === 'access' || op === 'optionalAccess') { lastAccessLHS = value; value = fn(value); } else if (op === 'call' || op === 'optionalCall') { value = fn((...args) => value.call(lastAccessLHS, ...args)); lastAccessLHS = undefined; } } return value; }/*! codelight.js 1.
|
|
1
|
+
"use strict";Object.defineProperty(exports, "__esModule", {value: true}); function _optionalChain(ops) { let lastAccessLHS = undefined; let value = ops[0]; let i = 1; while (i < ops.length) { const op = ops[i]; const fn = ops[i + 1]; i += 2; if ((op === 'optionalAccess' || op === 'optionalCall') && value == null) { return undefined; } if (op === 'access' || op === 'optionalAccess') { lastAccessLHS = value; value = fn(value); } else if (op === 'call' || op === 'optionalCall') { value = fn((...args) => value.call(lastAccessLHS, ...args)); lastAccessLHS = undefined; } } return value; }/*! codelight.js 1.1.1 | MIT License | https://github.com/codelightjs/codelight.js */
|
|
2
2
|
|
|
3
3
|
|
|
4
4
|
|
|
5
|
-
var
|
|
5
|
+
var _chunkKY23A6M5cjs = require('./chunk-KY23A6M5.cjs');
|
|
6
6
|
|
|
7
7
|
// src/react.ts
|
|
8
8
|
var _react = require('react');
|
|
@@ -10,9 +10,9 @@ var useIsomorphicLayoutEffect = typeof window === "undefined" ? _react.useEffect
|
|
|
10
10
|
function CodeLight({ code, lang, className, ...rest }) {
|
|
11
11
|
const ref = _react.useRef.call(void 0, null);
|
|
12
12
|
const view = _react.useRef.call(void 0, null);
|
|
13
|
-
const [initial] = _react.useState.call(void 0, () => ({ __html:
|
|
13
|
+
const [initial] = _react.useState.call(void 0, () => ({ __html: _chunkKY23A6M5cjs.highlight.call(void 0, code, lang) }));
|
|
14
14
|
useIsomorphicLayoutEffect(() => {
|
|
15
|
-
const v =
|
|
15
|
+
const v = _chunkKY23A6M5cjs.mount.call(void 0, ref.current, { lang });
|
|
16
16
|
v.set(code);
|
|
17
17
|
view.current = v;
|
|
18
18
|
return () => {
|
package/package.json
CHANGED
|
@@ -1,11 +1,15 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "codelight.js",
|
|
3
|
-
"version": "1.
|
|
4
|
-
"description": "
|
|
3
|
+
"version": "1.1.1",
|
|
4
|
+
"description": "Very fast, lightweight syntax highlighter. Highlights each line once and redraws only what changed, so live code never flickers. 19 languages, no dependencies, React or a script tag.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"syntax-highlighting",
|
|
7
7
|
"highlight",
|
|
8
8
|
"highlighter",
|
|
9
|
+
"syntax-highlighter",
|
|
10
|
+
"code-highlighting",
|
|
11
|
+
"lightweight",
|
|
12
|
+
"fast",
|
|
9
13
|
"code",
|
|
10
14
|
"streaming",
|
|
11
15
|
"stream",
|
|
@@ -21,7 +25,7 @@
|
|
|
21
25
|
],
|
|
22
26
|
"license": "MIT",
|
|
23
27
|
"author": "CK Giri <ckgdev@gmail.com>",
|
|
24
|
-
"homepage": "https://github.
|
|
28
|
+
"homepage": "https://codelightjs.github.io/",
|
|
25
29
|
"repository": {
|
|
26
30
|
"type": "git",
|
|
27
31
|
"url": "git+https://github.com/codelightjs/codelight.js.git"
|