This repository has been archived by the owner on Jan 25, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(sassoptions): create class for options interface
- Loading branch information
Showing
1 changed file
with
54 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
import { log } from '../util/logger'; | ||
import { wrapSassContext } from './wrapSassContext'; | ||
import { wrapSassOptions } from './wrapSassOptions'; | ||
|
||
interface SassOptionsInterface { | ||
/** | ||
* Release allocated memory with created instance. | ||
*/ | ||
dispose(): void; | ||
} | ||
|
||
/** | ||
* @internal | ||
* | ||
* Interop interface to `sass_option*` api | ||
* (https://github.com/sass/libsass/blob/master/docs/api-context.md#sass-options-api) | ||
* | ||
*/ | ||
class SassOptions implements SassOptionsInterface { | ||
/** | ||
* Raw pointer to `struct Sass_Options*` | ||
*/ | ||
private readonly sassOptionsPtr: number; | ||
/** | ||
* Construct new instance of SassOptions. | ||
* | ||
* @param {ReturnType<typeof wrapSassContext>} cwrapCtx cwrapped function object to sass context api. | ||
* @param {ReturnType<typeof wrapSassOptions>} cwrapOptions cwrapped function object to sass option api. | ||
* | ||
* Manual creation of this class is prohibited; | ||
* Should use `context.options.create` static interface instead. | ||
*/ | ||
constructor( | ||
private readonly cwrapCtx: ReturnType<typeof wrapSassContext>, | ||
private readonly cwrapOptions: ReturnType<typeof wrapSassOptions> | ||
) { | ||
this.sassOptionsPtr = cwrapCtx.make_options(); | ||
log(`SassOptions: created new instance`, { sassOptionsPtr: this.sassOptionsPtr }); | ||
} | ||
|
||
public get precision(): number { | ||
return this.cwrapOptions.option_get_precision(this.sassOptionsPtr); | ||
} | ||
public set precision(precision: number) { | ||
this.cwrapOptions.option_set_precision(this.sassOptionsPtr, precision); | ||
} | ||
|
||
public dispose(): void { | ||
this.cwrapCtx.delete_options(this.sassOptionsPtr); | ||
log(`SassOptions: disposed instance`); | ||
} | ||
} | ||
|
||
export { SassOptionsInterface, SassOptions }; |