Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add xcode light/dark theme #589

Merged
merged 2 commits into from
Dec 3, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions .changeset/seven-shirts-hide.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
"@codeimage/app": patch
"@codeimage/highlight": patch
---

feat: add xcode light/dark theme
10 changes: 10 additions & 0 deletions apps/codeimage/src/state/theme/themeRegistry.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,11 @@ export const THEME_REGISTRY: ReadonlyArray<ThemeRegistryEntry> = [
// prettier-ignore
load: () => import('@codeimage/highlight/themes').then(m => m.vsCodeDarkTheme),
},
{
id: 'xcodeDarkTheme',
// prettier-ignore
load: () => import('@codeimage/highlight/themes').then(m => m.xCodeDarkTheme),
},
{
id: 'nightOwlTheme',
// prettier-ignore
Expand All @@ -36,6 +41,11 @@ export const THEME_REGISTRY: ReadonlyArray<ThemeRegistryEntry> = [
// prettier-ignore
load: () => import('@codeimage/highlight/themes').then(m => m.draculaTheme),
},
{
id: 'xcodeLightTheme',
// prettier-ignore
load: () => import('@codeimage/highlight/themes').then(m => m.xCodeLightTheme),
},
{
id: 'materialOcean',
// prettier-ignore
Expand Down
2 changes: 1 addition & 1 deletion packages/highlight/dev/Editor/Editor.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ interface CustomEditorPreviewProps {
export default function Editor(props: VoidProps<CustomEditorPreviewProps>) {
const {editorView, ref: setEditorRef, createExtension} = createCodeMirror();
createEditorControlledValue(editorView, () => props.code);
createEditorReadonly(editorView, () => true);
createEditorReadonly(editorView, () => false);

const previewEditorBaseTheme = () =>
EditorView.theme({
Expand Down
16 changes: 15 additions & 1 deletion packages/highlight/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,14 @@
"./fleetDark": {
"import": "./dist/lib/themes/fleetDark/index.js",
"types": "./dist/lib/themes/fleetDark/index.d.ts"
},
"./xCodeDark": {
"import": "./dist/lib/themes/xCodeDark/index.js",
"types": "./dist/lib/themes/xCodeDark/index.d.ts"
},
"./xCodeLight": {
"import": "./dist/lib/themes/xCodeLight/index.js",
"types": "./dist/lib/themes/xCodeLight/index.d.ts"
}
},
"typesVersions": {
Expand Down Expand Up @@ -205,6 +213,12 @@
],
"fleetDark": [
"./dist/lib/themes/fleetDark/index.d.ts"
],
"xCodeDark": [
"./dist/lib/themes/xCodeDark/index.d.ts"
],
"xCodeLight": [
"./dist/lib/themes/xCodeLight/index.d.ts"
]
}
},
Expand Down Expand Up @@ -262,4 +276,4 @@
"vite-plugin-dts": "^1.7.3",
"vite-plugin-solid": "^2.6.1"
}
}
}
7 changes: 6 additions & 1 deletion packages/highlight/src/lib/plugins/highlight-style.ts
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,12 @@ export function styledHighlight(h: StyledHighlightOptions) {
color: h.numbers,
},
{
tag: [t.string, t.processingInstruction, t.inserted],
tag: [
t.string,
t.processingInstruction,
t.inserted,
t.special(t.string),
],
color: h.strings,
},
// Classes
Expand Down
2 changes: 2 additions & 0 deletions packages/highlight/src/lib/themes/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,3 +24,5 @@ export * from './shadeOfPurple';
export * from './synthwave84';
export * from './vitesseDark';
export * from './vsCodeDark';
export * from './xCodeDark';
export * from './xCodeLight';
16 changes: 16 additions & 0 deletions packages/highlight/src/lib/themes/xCodeDark/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import {createTheme} from '../../core';
import {palette, xCodeDark} from './xCodeDark';

export const xCodeDarkTheme = createTheme({
id: 'xCodeDark',
editorTheme: xCodeDark,
properties: {
darkMode: true,
label: 'XCode Dark',
previewBackground: `linear-gradient(to top, #a18cd1 0%, #fbc2eb 100%)`,
terminal: {
main: palette.foreground,
text: palette.text,
},
},
} as const);
85 changes: 85 additions & 0 deletions packages/highlight/src/lib/themes/xCodeDark/xCodeDark.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
import {HighlightStyle, syntaxHighlighting} from '@codemirror/language';
import {tags} from '@lezer/highlight';
import {defineEditorTheme} from '../../core';

const colors = {
pink: '#FF79B2',
violetLight: '#E5CFFF',
violet: '#D9BBFF',
purple: '#BB81FE',
cyan: '#5FBCDC',
orange: '#FE6465',
gray3: '#727377',
gray2: '#7F8C98',
green: '#8AD1C2',
green3: '#ACF2E4',
blue: '#4FB0CB',
yellow: '#FEE98B',
};

export const palette = {
foreground: '#1F1F24',
text: '#CECFD0',
text2: '#bebebe',
punctuation: '#fff',
numbers: colors.yellow,
strings: colors.orange,
property: colors.green,
keywords: colors.pink,
comments: colors.gray2,
className: colors.cyan,
function: colors.violet,
};

export const xCodeDark = [
syntaxHighlighting(
HighlightStyle.define([
{
tag: [tags.angleBracket],
color: colors.purple,
},
{
tag: [tags.definition(tags.variableName)],
color: colors.blue,
},
]),
),
defineEditorTheme({
highlight: {
punctuation: palette.punctuation,
delimiters: palette.punctuation,
numbers: palette.numbers,
strings: palette.strings,
regexp: palette.strings,
meta: colors.violet,
variableName: palette.property,
keywords: palette.keywords,
base: palette.text,
tag: colors.violet,
comments: palette.comments,
propertyName: palette.property,
className: palette.className,
function: palette.function,
typeName: colors.violetLight,
attrName: colors.purple,
},
selection: {
color: '#0000000f',
backgroundColor: '#0000000f',
activeLine: '#0000000f',
},
lineNumbers: {
color: palette.text2,
},
cursor: {
color: palette.text2,
},
autocomplete: {
background: '#202020',
border: '#3c3c3c',
selectedBackground: colors.purple,
selectedColor: '#fff',
},
darkMode: true,
}),
];
16 changes: 16 additions & 0 deletions packages/highlight/src/lib/themes/xCodeLight/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import {createTheme} from '../../core';
import {xCodeLight, palette} from './xCodeLight';

export const xCodeLightTheme = createTheme({
id: 'xCodeLight',
editorTheme: xCodeLight,
properties: {
darkMode: false,
label: 'XCode Light',
previewBackground: `linear-gradient(to right bottom, #ffcc99, #f6bd83, #edad6e, #e49e59, #da8f44)`,
terminal: {
main: palette.foreground,
text: palette.text,
},
},
} as const);
82 changes: 82 additions & 0 deletions packages/highlight/src/lib/themes/xCodeLight/xCodeLight.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
import {HighlightStyle, syntaxHighlighting} from '@codemirror/language';
import {tags} from '@lezer/highlight';
import {defineEditorTheme} from '../../core';

const colors = {
pink: '#c541ad',
violetDark: '#573E93',
violet: '#9157ea',
purple: '#59458B',
orange: '#D23423',
gray3: '#727377',
gray2: '#7F8C98',
blue: '#326C81',
darkBlue: '#322397',
darkGreen: '#1E566A',
};

export const palette = {
foreground: '#FFF',
text: '#191919',
text2: '#CACACA',
punctuation: '#1F1F24',
numbers: colors.darkBlue,
strings: colors.orange,
property: colors.darkGreen,
keywords: colors.pink,
comments: colors.gray2,
className: colors.darkGreen,
function: colors.violet,
};

export const xCodeLight = [
syntaxHighlighting(
HighlightStyle.define([
{
tag: [tags.angleBracket],
color: colors.purple,
},
{
tag: [tags.definition(tags.variableName)],
color: colors.blue,
},
]),
),
defineEditorTheme({
highlight: {
punctuation: palette.punctuation,
delimiters: palette.punctuation,
numbers: palette.numbers,
strings: palette.strings,
regexp: palette.strings,
meta: colors.violet,
variableName: palette.property,
keywords: palette.keywords,
base: palette.text,
tag: colors.violet,
comments: palette.comments,
propertyName: palette.property,
className: palette.className,
function: palette.function,
typeName: colors.darkGreen,
attrName: colors.purple,
},
selection: {
color: colors.gray3,
activeLine: '#ffffff0f',
},
lineNumbers: {
color: palette.text2,
},
cursor: {
color: palette.text2,
},
autocomplete: {
background: '#fff',
border: '#c5c5c5',
selectedBackground: colors.violetDark,
selectedColor: '#fff',
},
darkMode: true,
}),
];
Loading